First of all thanks a lot for this great module, which we're using since Drupal 6 with so many wonderful options.
Since GDPR is a major topic in EU countries, we're lacking a proper solution for several points when using Google Analytics with this module, for example:
- No proper integration with EU Cookie Compliance
- Do-Not-Track only works for logged in users and without static caching (doesn't work with boost e.g.)
- Cookies were set and (with local caching for GA Tracking code disabled) the tracking code was loaded from the Google servers if we used workarounds for GDPR compliance.
That reflects in a lot of issues in this module with many hacky workarounds posted, but no well working solution for end-users.
Drupal 8 issues:
#2917905: Add JS-function / method to set ga-disable-...
#2805127: DoNotTrack privacy feature
Drupal 7 issues:
#2173433: No GA code with alternative page caching engines and DNT header
#2971644: Eu cookie compliance support
This issue is a try to finally fix these typical problems with two patches, because it makes sense to combine the solution in a runtime JavaScript solution to allow static caching to work and also make interaction with other modules like eu_cookie_compliance possible. Because eu_cookie_compliance is widely used, I decided to also add it to the admin UI to have a better user experience for non-devs.
Here
Drupal 7:
- Google Analytics working patch: Attached below.
- If you'd like to combine this with EU Cookie Compliance you currently also need eu_cookie_compliance v7.x-1.30 or apply #2986131: JS loads too late to affect Google Analytics, Patch #7 on earlier versions.
Drupal 8:
- Blocked by core design. See #2986131: JS loads too late to affect Google Analytics which is blocked by core issue #2391025: Add support for inline JS/CSS with #attached.
- 8.x-2.x patch is prepared & ready but CAN NOT work without a solution in #2986131: JS loads too late to affect Google Analytics
- 8.x-3.x patch may be created by a volunteer based on 8.x-2.x but CAN NOT work without a solution in #2986131: JS loads too late to affect Google Analytics
So please help to push #2986131: JS loads too late to affect Google Analytics for Drupal 8!
Please test, review and comment the patch and please help adding tests so that we can roll this out for Drupal 8 and Drupal 7 as soon as possible.
Thank you all!
Comments
Comment #2
anybodyComment #3
anybodyComment #4
anybodyPatch for Drupal 7.x-2.x attached. Requires #2986131: JS loads too late to affect Google Analytics to work with EU Cookie Compliance (if used), until that issue is fixed.
Comment #5
anybodyFirst patch attempt for Drupal 7 and 8 attached. Please test, review and comment. The Drupal 7 version was tested a lot manually, the Drupal 8.x-2.x version was NOT tested manually yet, it is a code based upgrade from 7.x.
I'm not planning to create the 8.x-3.x release and like the idea from the matomo module to use a twig template for the JavaScript code a lot: #2948060: Implement twig template for tracking code customization which would mean major changes. If someone is willing to create a patch for 8.x-3.x you're welcome. Otherwise I'd like to wait if something happens into that direction. :)
Comment #8
anybodyFixed tests.
Comment #11
anybodyLast one for today... Does anyone have an idea how we can check https://developer.mozilla.org/en-US/docs/Web/API/Navigator/doNotTrack?
Comment #13
anybodyComment #14
anybodyComment #15
anybodyComment #17
anybodyNew patch which respects the eu_cookie_compliance "Automatic" setting (over DNT) and additionally fixed bugs in 8.x-2.x
Comment #19
anybodyComment #21
anybodyComment #23
anybodyComment #24
anybodyComment #25
anybodyYeah, 7.x and 8.x are finally passing... sorry for the many comments... Now please review :) I think this is a big step for GDPR in Google Analytics and EU Cookie Compliance.
Comment #26
anybodySee updated issue description, especially to see why 8.x CAN NOT work. Please test and review 7.x. It's working and we're already using it in production.
For Drupal 8 we could discuss to proceed with the patch in #24 from #2917905: Add JS-function / method to set ga-disable-... and improve it to fit @hass's requirements. It works differently so that the Drupal 8 core issue is workarounded.
Comment #27
anybodyComment #28
criscomThanks a lot for your efforts and the hard work you put in for this. This is very much appreciated.
We have tested the patch for D7 thoroughly in conjunction with the patch in https://www.drupal.org/project/eu_cookie_compliance/issues/2986131
We noticed that following:
In order for this feature [0] to work in conjunction with EU Cookie Compliance, the EU Cookie Compliance Extras module and the Google Analytics checkbox "EU Cookie Compliance integration" must be enabled [1].
[0]: https://screenshot.sunlime.at/d79663f36815b99c316683b84e28a5b0
[1]: https://screenshot.sunlime.at/a57e81fdf776e9fdba921ecd7a076b92
However, [0] only works with the Opt-in setting in the EU Cookie Compliance module: Opt-in. Don't track visitors unless they specifically give consent. (GDPR compliant) [2]
[2]: https://screenshot.sunlime.at/03bef05e36ca0dedeb6216a6ea27945a
If the Opt-out option in the EU Cookie Compliance module is selected [3], the GA code is initially not loaded and the users are not tracked until they click the "OK, I agree" button in the banner. See the video (open the link in Chrome to view the video) in [4]: the GA code is loaded after the consent button is clicked (not before as is expected).
[3]: https://screenshot.sunlime.at/3d9796eafe48a0ebb98fb0bd0eef3a69
[4]: https://screenshot.sunlime.at/a015a3f7eb949359e919be9f67ecd294
Not sure whether this is relevant for this issue or if this belongs to the EU Cookie Compliance issue queue. Thanks again for providing this patch as it helped a lot.
Comment #29
hass commentedIs there any progress in implementing a generic API in EU cookie compliance module where all modules around can integrate with so that all are using the same and there is no module specific code. EU cookie compliance need to provide the API from my point of view to implement a clean solution.
Comment #30
IckZ commentedFor the moment it looks like that this works perfect for my usecase (the new "EuGh Urteil")
Thank you a lot!
Comment #31
wranvaud commentedComment #32
4kant commentedHi Anybody,
your patch #17 for D7 gave me green light on every online-compliance checker. They say that the website is GDPR compliant.
I use EU Cookie Compliance module, version 7.x-1.31 - there is no patch necessary anymore.
Thanks a lot!
Comment #33
anybody@4kant and everyone else here: You may also want to try the EUCCX module for D7 with Google Analytics integration.
Comment #34
francescbassaspatch #17 applied on a D7, with EU Cookie Compliance module at 7.x-1.32, and worked as described
+1 to push this to a stable version. Thanks @anybody for the great work!
Comment #35
anybody@hass RE#29:
Could you perhaps have a look and provide feedback on #3130015: Write & document public JS API for actions & events
Some progress over there ;) ;)
Comment #36
phma commentedAfter I applied patch #17 on our D7 site, I'm getting an error if
googleanalytics_trackadsenseis set toTRUEby the user. It has to do with the order the scripts are loaded.The group is set to -101, so the
Drupalobject is not available in JavaScript yet. I have yet to find out if support for AdSense is a requirement for us or not. Just be aware of the limitation.EDIT: Seems like advagg_mod can help to work around this.
Comment #37
felubraI was unable to make this integration work with drupal/eu_cookie_compliance > 7.x-1.32. The Google Analytics script is always disabled because `eccHasAgreed` is always false even if the user agreed before.
Comment #38
drdam commentedSame problème
Comment #39
tfranz commentedSame here – i can't get it to work ...
Comment #40
tfranz commentedAs felubra pointed out, "eccHasAgreed" does not seem to work.
Instead I tried to read the value of the ecc-cookie "cookie-agreed" – that seems to work:
googleanalytics.module, patched with (Patch), lines 380ff:
Comment #41
mile23Currently using EUCC 7.x-1.37 with google_analytics 7.x-2.6, patched with #17 to good effect.
Comment #42
poker10 commentedAre there any chances this will be commited anytime soon? We have new e-Privacy directive comming into the force in 2022 and this directive strictly requires you to obtain the explicit consent from end-users before using cookies. So this issue will be crucial for all sites in EU in the next months.
See: https://www.cookiebot.com/en/eprivacy-regulation/ or https://www.lexology.com/library/detail.aspx
Comment #43
gngn commentedI just had to check an old D7 project using #17 - and encountered PHP notice:
Undefined variable: disabled in googleanalytics_form_user_profile_form_alter()
Taking a look I found that #17 removes the lines setting $disabled (from googleanalytics_form_user_profile_form_alter()):
and keeps the code directly after:
With that $disabled is used without ever assigning a value.
I think if we really do not need to disable the 'Enable user tracking' checkbox at all - than we should also remove the line
'#disabled' => $disabled,.Any thoughts?
Comment #44
csmdgl commentedRe-roll #17 for 7.x-2.8
Comment #45
mvcThis patch generally makes sense but is not compatible with the eu_cookie_compliance module's category feature. If the user has defined different categories (eg. required, performance, marketing) then Drupal.eu_cookie_compliance.hasAgreed() will always return true. We need to allow the user to specify which category includes GA, then check that the user has accepted that particular category by calling Drupal.eu_cookie_compliance.hasAgreed('category_name') instead.
Comment #46
summit commentedHi, It seems this is the god-issue about getting a noticeable effect on the cookies with any setting. In my case without a patch on latest eu_cookie module, It also does not reload the page after rejecting cookies. What to do please? And I am on Drupal 10 now?
Sorry for earlier making https://www.drupal.org/project/eu_cookie_compliance/issues/3425103, but after further investigation I found more issues about this.
Thanks for your reply in advance, greetings,