Last active
April 16, 2018 19:10
-
-
Save samba/afcb4941fc64ae89f0cbee9713785114 to your computer and use it in GitHub Desktop.
GTM Sampling Variable
This file contains hidden or 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
function(){ | |
// Sets and gets a sample ID for bucket selection in A/B and related testing methodologies. | |
var ckPattern = /sampleId=(\d+)/g; | |
var sampleId = -1; | |
// TODO: adopt a different method for selecting the corp top level domain | |
var domain = document.location.hostname; | |
document.cookie.replace(ckPattern, function($0, $d){ | |
sampleId = Number($d); | |
}); | |
if (sampleId < 0){ | |
sampleId = (Math.random() * 1E10) >>> 0; | |
document.cookie = ('sampleId=' + sampleId + '; path=/; domain=' + domain + ';'); | |
} | |
return sampleId; | |
} |
This file contains hidden or 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
function(){ | |
// Evaluate the sample ID into a specific bucket selection | |
var sampleId = {{sampleId}}; | |
var limit = 100; | |
var split = 70; // i.e. 30% are sampled as "true" | |
return (Number(sampleId) % limit > split) ? 'true' : 'false'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment