Skip to content

Instantly share code, notes, and snippets.

@lukefrake
lukefrake / experimentBucket.js
Last active December 6, 2021 10:29
Google Optimize Mutually Exclusive Experiments with Customer Javascript
// Use in the custom JavaScript section of Google Optimize to generate a group of buckets
// Change the %4 to %n to change the number of buckets
// Buckets are returned 0 index, so the following function will return 0, 1, 2 or 3
function() {
var group = localStorage.getItem('optimizeTestGroup');
if ( group ) return group
group = parseInt(ga.getAll()[0].get('clientId'))%4;
localStorage.setItem('optimizeTestGroup', group)
return group;
}