Optimize
3.6K members online now
3.6K members online now
Learn how to create your first experiment and get tips on creating A/B, redirect, and multivariate tests.
Guide Me
star_border
Reply

How do I change the woocommerce Google Analytics pro tracking code to use Google Optimize?

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I am using the Woocommerce Google Analytics Pro plugin and managed to change the tracking code on each page as follows:

 

<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','ga');
	ga( 'create', 'UA-XXXXXX-X', 'auto' , {'siteSpeedSampleRate': 100});
	ga( 'require', 'GTM-XXXXXX');
	ga( 'set', 'forceSSL', true );
	ga( 'require', 'ec' );</script>

 

But I get no results in Google Optimize. What could be the problem? Do I need to add?:

ga('send', 'pageview');

 Hope anyone can help.

How do I change the woocommerce Google Analytics pro tracking code to use Google Optimize?

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

Hi,

I just figured out how to do it. 

Open the "class-w-google-analytics-pro-integration.php" file

look for "<?php echo $this->get_ga_function_name(); ?>( 'create', '<?php echo esc_js( $this->get_tracking_id() ); ?>', 'auto' );

Right underneath that paste your optimize google code.

Optimize google is working now without problems.

 

Cheers,

Re: How do I change the woocommerce Google Analytics pro tracking code to use Google Optimize?

[ Edited ]
Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Since you use the Pro version of the plugin, you should probably add it without modifying the source code. There a hook for this. See https://github.com/skyverge/wc-plugins-snippets/blob/master/woocommerce-google-analytics-pro/add-cus...

 

Just place the above code in your functions.php file and replace ABC123 with your tracking code

Re: How do I change the woocommerce Google Analytics pro tracking code to use Google Optimize?

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
perfect, thanks!
I had added it to the source code but I guess this is better and safer
Have a great day


Virus-free.
www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>