I am using this module to allow visitors to opt out of receiving cookies from Google Analytics.

I followed this method https://www.drupal.org/node/1648286#comment-6145800 but it did not work because the javascript for GA was loaded before this one.

I noticed that in the eu_cookie_compliance.module file, js/eu_cookie_compliance.js was being loaded in the JS_THEME group. This group of scripts gets loaded last. I changed this line to use the JS_DEFAULT group instead, and I also changed the weight to 0, my thought being that we want this script to load before others so that it has a chance to block them.

This worked.

I think this should be a permanent change to the code and I'm happy to submit a PR but is there any reason why such a change might cause problems?

Drupal 7

Please review and test patch in #7

Drupal 8

Blocked by #2391025: Add support for inline JS/CSS with #attached, see comment #12

Comments

hoegrammer created an issue. See original summary.

hoegrammer’s picture

Issue summary: View changes
svenryen’s picture

I don't know. Guess we'll just have to test it and see how it performs. Nice if you can provide a patch.

hoegrammer’s picture

StatusFileSize
new806 bytes
svenryen’s picture

Thanks. I will take a look, but probably not before Sunday.

szeidler’s picture

Status: Active » Needs review

I recently encountered the same issue and was also wondering about the JS_THEME setting being too late. I fixed the issue with the same approach as the patch in #4.

I'm wondering if there would be a scenario, where the change could cause a regression on existing sites?

bwaindwain’s picture

Version: 7.x-1.25 » 7.x-1.28
StatusFileSize
new528 bytes

Here's the same patch updated for v1.28

qazema’s picture

I think we have the same problem in the D8 version, Google Analytics is not unset even if we specify the js file in "disable javascript". Is there already an issue posted about the D8 version of this problem ?

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Patch from #7 works great! Confirming RTBC, couldn't see any negative impacts.

This patch is also be needed for a eu_cookie_compliance integration in googleanalytics module proposed here: #3060312: Better GDPR compliance: Fix Do not track & EU Cookie Privacy integration

anybody’s picture

I agree with @Qazema, we need the same patch for Drupal 8. Any volunteers?

svenryen’s picture

Status: Reviewed & tested by the community » Needs work

A Drupal 8 version of the patch is required before we can commit.

anybody’s picture

Version: 7.x-1.28 » 7.x-2.x-dev
Issue summary: View changes

TL;DL:

We should RTBC the Drupal 7 version
We should create a follow-up issue for Drupal 8 because 8.x Google Analytics JS weight is blocked by #2391025: Add support for inline JS/CSS with #attached since years... and I guess it will still need years ...
Google Analytics tracking code is put as one of the first elements in head so we will NEVER cleanly be able to put our code before that, until that core issue is fixed.

More info:

Well... I just had a look and played around a lot... I can't see any solution for Google Analytics in D8 currently to move the JavaScript below the libraries (and especially after eu_cookie_compliance) like in D7. So I'd suggest to RTBC this for Drupal 7 as this is a 7.x blocker for #3060312: Better GDPR compliance: Fix Do not track & EU Cookie Privacy integration

Drupal 8 also needs this solution for #3060312: Better GDPR compliance: Fix Do not track & EU Cookie Privacy integration to work, but #2391025: Add support for inline JS/CSS with #attached blocks this and there's no solution.

So all in all I predict we won't have a Drupal 8 solution in the near future and block the Drupal 7 version from being updated, which makes no logical sense to me for this 7.x issue.

For Drupal 8 I suggest we need to push a solution for #2391025: Add support for inline JS/CSS with #attached to put the Google Analytics Script a lot lower like @hass already wrote there several times. I completely agree with him.
There is a long history in GA 8.x issues like #2890438: Clean way to avoid inline js?, #2753215: Put ga script lower in head tags and others, wich all end up in that core issue.

svenryen’s picture

Status: Needs work » Reviewed & tested by the community

Setting this to RTBC and scheduling it for committing to D7 branch following the request in #12.

  • bwaindwain authored 40e8120 on 7.x-1.x
    Issue #2986131 by hoegrammer, bwaindwain, svenryen, Anybody: JS loads...
svenryen’s picture

Status: Reviewed & tested by the community » Fixed
anybody’s picture

Great!! :) Thank you @svenryen
Looking forward to 7.x-1.30 ! :)

criscom’s picture

We tested the patch. It works in conjunction with https://www.drupal.org/files/issues/2019-07-10/googleanalytics-7.x-2.x-b... when set to Opt-in. Don't track visitors unless they specifically give consent. (GDPR compliant)

It didn't work with Opt-out. Track visitors by default, unless they choose to opt out. The Google Analytics cookies were not removed after clicking Decline.

anybody’s picture

Thank you @criscom,

I guess it's not the fault of this patch. Please comment the Google Analytics issue accordingly instead. This patch does what it should.

criscom’s picture

Ok, thanks for the heads-up. I added it to one of the issues in the GA issue queue where you contributed as well: https://www.drupal.org/project/google_analytics/issues/3060312#comment-1...

  • bwaindwain authored 40e8120 on 7.x-2.x
    Issue #2986131 by hoegrammer, bwaindwain, svenryen, Anybody: JS loads...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.