• Resolved kickaxe

    (@kickaxe)


    How do you all go about inserting your google experiment code when you use the Monster Insights plugin? It seems to add the google tracking code as the 1st element after the <head> tag but to do a Google Experiment, you need the google experiment script BEFORE the Google Analytics element.

    Would love some feedback, couldn’t find a clear explanation on this.

    View post on imgur.com

    • This topic was modified 7 years, 8 months ago by kickaxe.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author chriscct7

    (@chriscct7)

    Hi there,
    What are you using to insert the Google Analytics experiments JS?

    -Chris

    Thread Starter kickaxe

    (@kickaxe)

    I am inserting it in my functions.php with the following code.

    add_action(‘wp_head’,’my_analytics’, 1);

    function my_analytics() {
    ?>

    <!– Google Analytics Content Experiment code –>
    echo <script>function utmx_section(){}function utmx(){}(function(){var
    k=’102172312-7′,d=document,l=d.location,c=d.cookie;
    if(l.search.indexOf(‘utm_expid=’+k)>0)return;
    function f(n){if(c){var i=c.indexOf(n+’=’);if(i>-1){var j=c.
    indexOf(‘;’,i);return escape(c.substring(i+n.length+1,j<0?c.
    length:j))}}}var x=f(‘__utmx’),xx=f(‘__utmxx’),h=l.hash;d.write(
    ‘<sc’+’ript src=”‘+’http’+(l.protocol==’https:’?’s://ssl’:
    ‘://www’)+’.google-analytics.com/ga_exp.js?’+’utmxkey=’+k+
    ‘&utmx=’+(x?x:”)+’&utmxx=’+(xx?xx:”)+’&utmxtime=’+new Date().
    valueOf()+(h?’&utmxhash=’+escape(h.substr(1)):”)+
    ‘” type=”text/javascript” charset=”utf-8″><\/sc’+’ript>’)})();
    </script><script>utmx(‘url’,’A/B’);</script>
    <!– End of Google Analytics Content Experiment code –>

    <?php
    }

    Thread Starter kickaxe

    (@kickaxe)

    I managed to get this working by inserting it with the add_action method and passing in a negative -10 for the 3rd parameter which is priority.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Google Experiments (A/B Test) and Monster Insights Plugin’ is closed to new replies.