Last active
August 29, 2015 14:08
-
-
Save yoavmatchulsky/dcbd29497bf3f12c2516 to your computer and use it in GitHub Desktop.
Only show GA content experiment to mobile traffic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
////// START EDITING HERE | |
var utmx_key = 'XXXXXXX-X', // change this to your experiment key | |
show_on = 'mobile', // Can be 'mobile' or 'desktop' | |
///// STOP EDITING HERE | |
/////////////////////////// | |
is_mobile = function () { | |
return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera\s?mini/i.test(navigator.userAgent.toLowerCase()); | |
}, | |
show_experiment = function() { | |
return (show_on === 'mobile' && is_mobile()) || (show_on === 'desktop' && !is_mobile()); | |
}, | |
utmx_section = function() { }, | |
utmx = function() { }; | |
if ( show_experiment() ) { | |
// <!-- Google Analytics Content Experiment code --> | |
function utmx_section(){}function utmx(){}(function(){var | |
k=utmx_key,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 --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment