Problem/Motivation
With "Consent method: opt-in" if I put some script with syntax "path/to/the/script.js" in "Disable JavaScripts" with "Enable cookie(s) automatic-removal when consent isn't given" everything seems to work as expected. Untill I agree the script is not working, after i agree the script is working and cookies setted up.
If i use che same script with the "Opt-in with categories" , and I put inside "Disable JavaScripts" the line with syntax category:path/to/the/script.js with "Enable cookie(s) automatic-removal the script seems to never load, even if i agree for the specific category.
If i check the browser cookies are not setted up.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | convert-relative-uris-with-categories-3254826-14.patch | 481 bytes | csmdgl |
| #11 | Screenshot (1).png | 126.55 KB | brandonlira |
| #10 | convert-relative-uris-with-categories-3254826-10.patch | 674 bytes | phma |
Issue fork eu_cookie_compliance-3254826
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3254826-disabling-javascript-with
changes, plain diff MR !60
Comments
Comment #4
svenryen commentedI'm afraid I can't reproduce.
Does your script in any way utilize drupal behaviors?
I set up a sample module "sven_test_1" and added a sample script using
drush generate javascript.This produced the following script:
I then set up a single category "test", and configured my "Disable JavaScripts" settings like this:
test:modules/custom/sven_test_1/js/sven-test-1.js|svenTest1SvenTest1This resulted in the following script being generated and included in the page source:
After consenting to the category "test" I was able to see "It works!" in my console, so from my experience, this feature works, also with categories.
Comment #6
Youcanlearnit commentedI have the exact same problem, with version 1.24.
If I put in the "disabled javascripts" box for example:
stat_cookies:https://www.googletagmanager.com/gtag/js
It will never load that library, even the user gives consent.
I have selected:
Opt-in with categories.
and a category with machine name: stat_cookies.
Comment #7
svenryen commentedWhich module provides that script, @Youcanlearnit?
Comment #8
Youcanlearnit commentedHi,
I think it was this:
https://www.drupal.org/project/google_analytics/releases/4.0.2
Comment #9
phma commentedI've come across a similar problem just now and it could be related.
When you operate the drupal site from a sub path, path prefix gets added to the category in the JavaScript snipped that should load the scripts after accepting cookies.
The reason for this is that
_eu_cookie_compliance_explode_multiple_linesis processing entries and tries to convert relative paths while not taking into consideration that some of them are prefixed with a category. It seems to work if Drupal is ran from root, but not when it's in a sub path.So the category needs to be split either before or inside
_eu_cookie_compliance_convert_relative_uri. Else the result it produces is pretty useless.Comment #10
phma commentedThe latest release writes the JavaScript into a separate file (I hadn't updated yet). This means if I now save the config while Drupal is served from the root path, it mitigates the problem. Still, it could break again if config is imported or if config is accidentally saved and a path prefix gets re-added.
The easiest solution I found is to filter out the path from the category name with
basename, but that means categories containing slashes (or backslash on Windows) will not work. In general it would be better to extract the path before processing relative URIs. But that would require more refactoring and testing.Comment #11
brandonlira commentedDoes anyone have any updates on this, I'm also facing this issue even trying to add to DISABLE THE FOLLOWING JAVASCRIPTS WHEN CONSENT ISN'T GIVEN they are still loading as per this example analytics:sites/default/files/google_tag/google_tag.script.js, I've updated for the last version but without success and the available patch was also applied.
Does anyone have any ideas or suggestions?
Comment #12
svenryen commentedComment #13
svenryen commentedI'm not the most experienced GTM/GA user, but I did set up an account at https://tagmanager.google.com/#/home and https://analytics.google.com/analytics/web/.
Best practice nowadays seems to be using the google_tag module, so I installed, enabled and configured that module to load my GTM tag.
Once that's set up and confirmed working, I set up my site to Opt-in users to tracking and listed the two scripts of the google_tag module in "Disable JavaScripts".
The value of the field is:
I also tried the same setup with a category added to the mix:
Loading that page in a few incognito windows demonstrates that there's no GA traffic recorded until the consent was given, and after it was given, the googletagmanager script loads and records my activity in GA4.
It seems this module doesn't create a sites/default/files/google_tag/google_tag.script.js file. Could you add some information as to what module provides that file? Is it possible to attempt using the google_tag module to achieve your desired outcome, or is there some feature google_tag lacks?
Comment #14
csmdgl commentedRe-roll for 1.26.
Comment #15
atowl commentedHi All,
Could i get an update for this with someone using 1.28? and if it's still a potential issue?
Comment #16
atowl commentedHi,
Since there is no new information, i'm closing this. If its still an issue, please feel free to reopen
Thanks