Optimize
4.1K members online now
4.1K members online now
Everything you need to know about setting up Optimize including creating your account and container, linking to Google Analytics and how to tag your site.
Guide Me
star_border
Reply

Integration Google Optimize and Wordpress (WooCommerce)

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi there, is there a way to integrate Google Optimize wordpress (woocommerce)?

 

Hope to hear, thanks in advance!

=======================

Add Optimize to your website
Optimize is installed on your site by adding a single line of code (shown in bold) to your existing Universal Analytics (analytics.js) tracking code. If you don’t have Google Analytics or if you’re using Google Tag Manager, please refer to the Optimize help center.
To install Optimize, do the following on each page you want to test:
Ensure that your Analytics tracking code is as high as possible in the <HEAD> of every page.
Add the line in bold below to your tracking code.
<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-xxxx-1’, ‘auto’);
ga(‘require’, ‘GTM-MT26PR6’);
ga(‘send’, ‘pageview’);
</script>

  • This topic wa
 
Recommended: Page hiding
When experiment variants are applied, users may very briefly see the original content. To minimize this, use the following snippet, which prevents users from seeing your page before a variant is applied, or times out on slower connections. Learn more about page hiding.
To install page hiding:
  1. Copy the full code below and add it to every page with Optimize as early in the <HEAD> as possible.
  2. Ensure that your updated Google Analytics tracking code immediately follows your hiding code.
<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-MT26PR6':true});</script>
Learn more about other ways to deploy Optimize, including serving it with Google Tag Manager, in the Optimize help center.
1 Expert replyverified_user

Integration Google Optimize and Wordpress (WooCommerce)

Top Contributor
# 2
Top Contributor

how do you track GA in wordpress right now?

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Integration Google Optimize and Wordpress (WooCommerce)

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks for your prompt reply, now i do this through an plugin, see: WooCommerce Google Analytics Integration. Here there is no option to integrate the extra steps Google Optimize requires (add extra rule in google analytics code).

Marked as Best Answer.
Solution
Accepted by Jason O (Community Manager)
August

Re: Integration Google Optimize and Wordpress (WooCommerce)

Top Contributor
# 4
Top Contributor

OK try this at your own risk.

In your extensions folder, locate woocommerce-google-analytics-integration/includes/class-wc-google-analytics-js.php

Find line that says

$support_display_advertising .

*ABOVE* THAT, ADD THE FOLLOWING

self::tracker_var() . "( 'require', 'GTM-MT26PR6' );" .

 

Your (non-extensive) end result should look something like: 

 

$code = "(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','//www.google-analytics.com/analytics.js','" . self::tracker_var() . "');

		" . self::tracker_var() . "( 'create', '" . esc_js( self::get( 'ga_id' ) ) . "', '" . $set_domain_name . "' );" .
		self::tracker_var() . "( 'require', 'GTM-MT26PR6' );" .
		$support_display_advertising .
		$anonymize_enabled . "
		" . self::tracker_var() . "( 'set', 'dimension1', '" . $logged_in . "' );\n";

		if ( 'yes' === self::get( 'ga_enhanced_ecommerce_tracking_enabled' ) ) {
			$code .= "" . self::tracker_var() . "( 'require', 'ec' );";
		} else {
			$code .= "" . self::tracker_var() . "( 'require', 'ecommerce', 'ecommerce.js');";
		}

		return $code;

And of course you'll need to maintain that code every time your plugin is updated

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Integration Google Optimize and Wordpress (WooCommerce)

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Thanks Julien, i'll give that a try!

Integration Google Optimize and Wordpress (WooCommerce)

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

any luck with this? in the same situation myself!

Integration Google Optimize and Wordpress (WooCommerce)

Top Contributor
# 7
Top Contributor

pretty sure my hack works :-)

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Integration Google Optimize and Wordpress (WooCommerce)

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭

Salut Julien Smiley Happy

I have the same issue, but not exactly the same plugin.

Mine is: Enhanced E-commerce for Woocommerce store (Version 1.0.16by http://www.tatvic.com/)

The file is  enhanced-e-commerce-for-woocommerce-store/includes/class-wc-enhanced-ecommerce-google-analytics-integration.php

But I can't fine the line

$support_display_advertising .

 

Un grand merci Smiley Happy

Florian

Integration Google Optimize and Wordpress (WooCommerce)

Top Contributor
# 9
Top Contributor

@Florian M my mod only applies to the official plugin :-(

If you'd like, create a user account on your WP with admin rights for address julien.coquet at gmail dot com and i'll take a look

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Re: Integration Google Optimize and Wordpress (WooCommerce)

Visitor ✭ ✭ ✭
# 10
Visitor ✭ ✭ ✭

Hi Julien, thanks for your quick feedback.

I'm not sure that I'm allowed to do that by my management.

If I send you by mail the content of the plugin (2 PHP files), would that make it?

Thanks Smiley Happy