Tagged: x
-
AuthorPosts
-
September 29, 2016 at 5:58 pm #1196453
Hey there,
I was reading this thread https://community.theme.co/forums/topic/google-content-experiments-3/
and got it working to run one experiment on my site. Now I want to run another one and can’t quite get the code to work.
I tried this and doesn’t work:
add_action('wp_head', 'add_code_function'); function add_code_function() { if ( is_page( 371 ) ) { ?> <!-- Google Analytics Content Experiment code --> <script>function utmx_section(){}function utmx(){}(function(){var k='127668256-2',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 } } if ( is_page( 534 ) ) { ?> <!-- Google Analytics Content Experiment code --> <script>function utmx_section(){}function utmx(){}(function(){var k='127668256-2',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 } }
What do I have to do to the php to add anohter experiment code to another page?
Thanks for any help!
September 29, 2016 at 10:55 pm #1196847Hi There,
Thanks for writing in! Please update your code to this:
add_action('wp_head', 'add_code_function'); function add_code_function() { if ( is_page( 371 ) ) : ?> <!-- Google Analytics Content Experiment code --> <script>function utmx_section(){}function utmx(){}(function(){var k='127668256-2',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 endif; if ( is_page( 371 ) ) : ?> <!-- Google Analytics Content Experiment code --> <script>function utmx_section(){}function utmx(){}(function(){var k='127668256-2',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 endif; }
Hope it helps, Cheers!
October 3, 2016 at 1:14 pm #1200787Thanks! That works!
Cheers,
JesseOctober 3, 2016 at 1:17 pm #1200793You are most welcome. 🙂
-
AuthorPosts