Using Google optimize snippet with Google Analytics +

I’m trying to add Google optimize snippet into existing Analytics tracking code –

Looking into Google Analytics + plugin but can’t find any option where that can be added.

The Analytics code seems to be inserted in page head tag automatically by the plugin, what I want to do is inserting the additional snippet required there for Google Optimize using GA+.

ga('require', 'GTM-XXXXXX');

  • Nastia
    • Support Rock Star

    Hello Michael

    Hope you’re doing well!

    Out of the box, with Google Analytics+ plugin this is not possible. To deploy Optimize a snippet needs to be added in the header of a site. Feel free to add a code in the head.php of a child theme, look for a tag <head> inside and add the code right below it. If a child theme is not created on your site, please see How to Create a WordPress Child Theme. Make sure you’ve created a backup before switching to another theme.

    Another way is to use a plugin that injects JS code into a header or a footer:

    To implement this inside the plugin a lot of custom coding required, we flagged our developers in this thread to provide some feedback if this is possible.

    Have a good day and take care!



  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hi Michael !

    Could you please try adding the following code into your functions.php ( preferably your child themes )? We have a hook that you can easily add as many extra vars you want into the existing GA snippet. Of course you’ll have to change the “GTM-XXXXXX” into anything that is used for your live site.

    add_action( 'ga_plus_network_tracking_code_add_vars', 'add_extra_vars_to_ga' );
    function add_extra_vars_to_ga() {
    $var = "ga('require', 'GTM-XXXXXX');";
    echo $var;

    Tell me if this works for you!



Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.