Skip to content

Instantly share code, notes, and snippets.

@Pross
Created June 2, 2016 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pross/144bc6656e1a35d369f214c0cfb5d019 to your computer and use it in GitHub Desktop.
Save Pross/144bc6656e1a35d369f214c0cfb5d019 to your computer and use it in GitHub Desktop.
//Google Experiment Code
function google_experiment_code() {
// NOTE replace 123 with your page ID
if( is_page(123) ) {
?>
<!-- Google Analytics Content Experiment code -->
<script>function utmx_section(){}function utmx(){}(function(){var
k='30041124-5',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
}
}
add_action( 'wp_head','google_experiment_code', 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment