Support » Plugin: GTM4WP - A Google Tag Manager (GTM) plugin for WordPress » Google Tag Manager and Google Experiments / Google Optimize

  • Resolved johson

    (@johson)


    Hi Thomas,

    First of all, thank you again for this amazing plugin!

    I have GTM installed for a long time now. I was invite to Google Optimize / Experiments. So I followed all the steps: I created an accound and linked it to my GA, to the appropriate view. Then I added the Optimize snippet as provided in Google Optimize.

    First of all, I did not change the code I had in my template file, because I have the ‘Custom’ option set in GTM plugin. I have this code just after the opening <body> tag:
    <?php if ( function_exists( ‘gtm4wp_the_gtm_tag’ ) ) { gtm4wp_the_gtm_tag(); } ?>

    In that same file, I added this provided code by Google Optimize just below the closing HEAD tag:
    <script>
    (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,’script’,’https://www.google-analytics.com/analytics.js&#8217;,’ga’);
    ga(‘create’, ‘UA-XXXXXXetc.’, ‘auto’);
    ga(‘require’, ‘GTM-XXXXXetc.’);
    ga(‘send’, ‘pageview’);
    </script>

    <style>.async-hide { opacity: 0 !important} </style>
    <script>(function(a,s,y,n,c,h,i,d,e){s.className+=’ ‘+y;h.start=1*new Date;
    h.end=i=function(){s.className=s.className.replace(RegExp(‘ ?’+y),”)};
    (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
    })(window,document.documentElement,’async-hide’,’dataLayer’,4000,
    {‘GTM-XXXXXXetc’:true});</script>

    Of course, with the right GTM and UA codes.

    However, If you check my site with Tag Assistant plugin, you will notice that there is an error: ‘Same web property ID is tracked twice.’

    I have tried to first load the async code first. I have also tried to place both snippets of code to the top of the head section. Same results.

    I have also tried deleting the ‘ga(‘create’, ‘UA-XXXXXXetc.’, ‘auto’);’ part of the snippet, but got an error in the experiment preview, that the required code was not installed correctly.

    Furthermore, on some other pages than my home page, I am also getting this error in Tag Assistant: ‘Multiple installations of Google Tag Manager detected’. It is referring to the GTM code for google optimize.

    Do you have any idea how I could resolve this? I hope you can help.

    This is my website: https://www.vgpjewelry.nl

    • This topic was modified 7 years ago by johson.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Thomas Geiger

    (@duracelltomi)

    Hi Johson,

    You do not need to add the full Optimize code into your header.php, because there is a Google Optimize tag template on the GTM UI. You should only add the so called page hiding snippet to your template:

    
    <style>.async-hide { opacity: 0 !important} </style>
    <script>(function(a,s,y,n,c,h,i,d,e){s.className+=’ ‘+y;h.start=1*new Date;
    h.end=i=function(){s.className=s.className.replace(RegExp(‘ ?’+y),”)};
    (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
    })(window,document.documentElement,’async-hide’,’dataLayer’,4000,
    {‘GTM-XXXXXXetc’:true});</script>
    

    With your current setup, you are tracking all pageviews twice, just as Tag Assistant reports the issue.

    I hope that helps,
    Thomas Geiger

    Thread Starter johson

    (@johson)

    Hi Thomas,

    Thank you so much for your fast reply!

    I have adjusted the head as you said. I only have the hiding snippet now.

    However, when I check my site with google tag manager, all seems to be working ok, but I do not see my new GTM optimize tag anywhere.

    But the biggest problem is this error when I get whenever I am in Google optimize and I click on the preview button of an experiment. I am affraid my experiments have stopped working. I have left the code as you suggested though, in the hopes you would be so kind to take another look. See screenshot of the error: Error optimize snippet

    Plugin Author Thomas Geiger

    (@duracelltomi)

    Hi Johson,

    Have you added the Google Optimize tag manually into your container?
    http://www.awesomescreenshot.com/image/2338443/1268acc3ce51b299ee9a34bedfc05ae8

    Thomas

    Thread Starter johson

    (@johson)

    Wow! That was fast!

    Could you point me to an article or something on how to do that?

    I am so sorry. I have a bit of experience with GTM, but this whole Google Optimize is new to me, and also the combo of both. But the potential power of the combo. Wow!

    Plugin Author Thomas Geiger

    (@duracelltomi)

    Hi,

    Try this article, let me know if this is not what you are looking for:
    https://support.google.com/tagmanager/answer/7164339?hl=en

    Thomas

    Thread Starter johson

    (@johson)

    This was exactly what I was looking for. THANKS!

    I followed the article (as best as I could anyway…) and I do not get that error anymore when previewing the experiment variants. So I guess it is working properly now.

    However, I am not sure. This is where I did not understand anymore. I will elaborate the points mentioned in the article you send me:

    Tag setup
    Done: Click Tags → New.
    Done: Change the default name of “Untitled Tag” to a descriptive title, such as “Optimize – http://www.example.com&#8221;
    Done: Click Tag Configuration → Google Optimize.
    Done: Enter your Google Analytics Tracking ID and your Optimize container ID (a.k.a. the Optimize snippet ID, available the Optimize Container setup panel.)
    Not Done: Click More settings, and configure the Fields to Set and Advanced Configuration with the same values as your Google Analytics tags.
    Done: Click Save, and proceed to save the tag without triggers.
    Done: Open any Google Analytics Page View tags that are being triggered on load of pages where you want the Google Optimize tag to be fired.
    Done: Click to edit the Tag Configuration, and open Advanced Settings → Tag Sequencing.
    Check the box to fire a tag before this tag fires, and select your Google Optimize tag as a “Setup Tag”.
    Done: Click to Save your Google Analytics Page View tag, and repeat on any other Google Analytics Page View tags as relevant.

    At the Not Done part, I did not know which fields to select. And if only the Analytics ID or both the Analytics ID and the GTM Optimize ID had to be set. Again, no idea what fields to select to set these values in…

    Thread Starter johson

    (@johson)

    Hi Thomas,

    I have been monitoring my experiments today and your suggestion was the solution!

    Thank you SO MUCH again! You are the BEST!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Google Tag Manager and Google Experiments / Google Optimize’ is closed to new replies.