• Resolved g-mcfadyen

    (@g-mcfadyen)


    I am trying to add my Google Analytics script to the HEAD section for non-neccessary cookies –
    // Google Analytics
    <!– Global site tag (gtag.js) – Google Analytics –>
    async src=”https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX&#8221;
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag(‘js’, new Date());

    gtag(‘config’, ‘G-XXXXXXXX’);

    Is this the correct script to add? I have looked for various solutions, none of which have worked, and I can’t find anything on the support forum that shows specifically what (complete) code/script to add to the HEAD field to make this work. Please help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author WebToffee

    (@webtoffee)

    Hi @g-mcfadyen,

    Here s a sample code. You should add the script tags too in the script input fields.

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxx"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'UA-xxxxxxxxxx');
    </script>
    Thread Starter g-mcfadyen

    (@g-mcfadyen)

    I tried that but it didn’t work. I tried it in the body field too, and that didn’t work either. I’ve tried putting the GA script in a separate JS file and using the head field to call that – that didn’t work either.

    When I first installed the plugin, the head field contained some example script which looked like it called a specific function, which I’m presuming is included in the plugin?

    Thread Starter g-mcfadyen

    (@g-mcfadyen)

    I see this in the <head> region –
    <script type=’text/javascript’>
    /* <![CDATA[ */
    var Cli_Data = {“nn_cookie_ids”:[“GA1.2.2104776523.XXXXXXXXXX”,”GA1.2.1791343158.XXXXXXXXXX”,”1″],”cookielist”:[]};
    var log_object = {“ajax_url”:”https:\/\/mydomain.com\/wp-admin\/admin-ajax.php”};
    /* ]]> */
    </script>

    These details correspond to the non-necessary cookie IDs/Values for the site, that I’ve added to the Cookie List. However, no matter what I add to the HEAD field, the <head> HTML does not change.

    Just to add, mydomain is not yet on https…

    • This reply was modified 5 years, 1 month ago by g-mcfadyen.
    Plugin Author WebToffee

    (@webtoffee)

    Hi @g-mcfadyen,

    We require the site URL to check it further.

    Thread Starter g-mcfadyen

    (@g-mcfadyen)

    The URL is https://hscpprod.wpengine.com/

    The site is not yet ‘live’ insomuch as the domain name has not been sorted yet.

    Plugin Author WebToffee

    (@webtoffee)

    Hi @g-mcfadyen,

    We suspect there is some cache implementation in place in your site which is causing the trouble.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add Google Analytics script’ is closed to new replies.