Skip to content

Instantly share code, notes, and snippets.

@mmoravec
Created December 15, 2015 04:10
Show Gist options
  • Save mmoravec/38ec3e9e5911c83e517b to your computer and use it in GitHub Desktop.
Save mmoravec/38ec3e9e5911c83e517b to your computer and use it in GitHub Desktop.
<script type="text/javascript">
function getOptimizelyTestMap(e) {
if ("undefined" != typeof window["optimizely"]) {
var allTests = window["optimizely"].allExperiments
, charCount = 0
, siteCatalyst = s_gi(s_account)
, variationMap = window["optimizely"].variationMap
, variationMapActive = [] // Leave behind only tests that are still running
;
for (var testId in variationMap) {
if (variationMap.hasOwnProperty(testId)) {
var map = []
, mapString = ""
, testDefined = false
, testEnabled = false
;
testDefined = allTests.hasOwnProperty(testId);
testEnabled = testDefined && allTests[testId].hasOwnProperty("enabled");
if (testEnabled) {
map = [].concat(variationMap[testId]).join("_");
mapString = testId + ":" + map;
if ((charCount + mapString.length) <= 255) {
// Only add if we won't exceed the 255 character cap
charCount += mapString.length;
variationMapActive.push(mapString);
}
}
}
}
siteCatalyst["eVar" + e] = variationMapActive.join();
}
}
// Make the function call, passing in the eVar number
getOptimizelyTestMap(15);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment