javascript - Include Google experiment code in template header for specific pages -



javascript - Include Google experiment code in template header for specific pages -

i need add together google experiments code in 2 pages a/b testing. code has within header section of template, otherwise won't work.

this i've tried on template:

<?php $titulo=substr($_server['request_uri'], 0, 10); if($titulo=='/experience'){ echo '<script type="text/javascript" src=".../exp.js"></script>'; } ?>

the if statement working ok, including exp.js script pages want.

this exp.js

<!-- google analytics content experiment code --> <script>function utmx_section(){}function utmx(){}(function(){var k='15950497-1',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 -->

this returning error:

uncaught syntaxerror: unexpected token <

on line 2 of exp.js

i've tried echo script straight on template creates syntax error quotes (i tried both simple , double).

is there way prepare this?

thanks in advance help!

change echo to:

print file_get_contents(dirname(__file__).'/../exp.js');

javascript php

Comments