Getting google analytics to work

Created on 20 June 2012, over 12 years ago
Updated 6 September 2023, over 1 year ago

Has anyone had any success getting the google analytics code to work? When I try to insert the code from dagomar's post I get this error:

Do not add the tracker code provided by Google into the javascript code snippets! This module already builds the tracker code based on your Google Analytics account number and settings.

💬 Support request
Status

Closed: duplicate

Version

1.0

Component

Miscellaneous

Created by

🇬🇧United Kingdom Boffy31

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • To be able to use the hasAgreed() function, I relied on the observer pattern provided by the library

    It can be done this way in order to declare a function which will be called after the cookie value has been loaded and the hasAgreed function works.
    (beware, it is actually called twice, so you may want to protect your function against being called twice)

    Drupal.eu_cookie_compliance("postStatusLoad", function postLoadHandle(scope,o) {
      if (Drupal.eu_cookie_compliance.hasAgreed()){
       //GOOGLE ANALYTICS CODE
      }
      else {
       // DISABLE GOOGLE ANALYTICS CODE
      }
      });
  • Hello everyone,

    I got this task to make our web site from work GDPR compliant.
    So here we are, they gave me the drupal user and I need to find solution.
    First time I work with Drupal and I try already with days to fix the issue.
    As i dont understand where I have to put the above functionalities for disabling the Google Analytics ,
    can some one point me where exactly I need to put the code?
    I am trying in the Header Footer Scripts Settings in the configuration of Drupal,
    and here where the google analytics is set, under neath I am putting this code:

    if (!Drupal.eu_cookie_compliance.hasAgreed()){ window['ga-disable-UA-XXXXXXXX-1'] = true; } ga("send", "pageview");

    But still when i try to check the web site, the report is coming back for Google Analytics:
    Blocked until accepted by user: No
    I would much appreciate any help cause I am already stuck with days and I need to fix this issue asap.
    Thank you

Production build 0.71.5 2024