Skip to content

Instantly share code, notes, and snippets.

@dsignr
Created January 13, 2017 02:58
Show Gist options
  • Save dsignr/5902d668adec8fb109d9eb9a7d8d5568 to your computer and use it in GitHub Desktop.
Save dsignr/5902d668adec8fb109d9eb9a7d8d5568 to your computer and use it in GitHub Desktop.
Simple split test
var siteEvent;
var siteSplit;
jQuery(function() {
siteEvent = function(c, a, l, v) {
dataLayer.push({
'event': 'siteEvent',
'siteEventCategory': c,
'siteEventAction': a,
'siteEventLabel': l,
'siteEventValue': v
});
};
var swipeFiles = {
content: {
headlines: ["a", "b", "C"],
descriptions: ["a", "b", "c"],
backgrounds: ["a", "b", "c"],
icons: ["a", "b", "c"]
},
actions: {
headlines: {
set: function(headline) {
$('*[data-split-headline]').text(headline);
}
},
descriptions: {
set: function(description) {
$('*[data-split-description]').text(description);
}
},
backgrounds: {
set: function(background) {
//TODO
}
},
icons: {
set: function(icon) {
//TODO
}
}
}
}
function generateSplitElement(element) {
console.log(store.get(element));
if (store.get(element) == null) {
var max = swipeFiles.content[element + "s"].length - 1
var randomNumber = Math.floor(Math.random() * (max + 1));
var swipe = swipeFiles.content[element + "s"][randomNumber];
store.set(element, swipe);
console.log(element, swipe);
} else {
var swipe = store.get(element);
swipeFiles.actions[element + "s"].set(swipe);
}
}
var splitHeadline = store.get("headline");
var splitDescription = store.get("description");
var splitBackground = store.get("background");
var splitIcon = store.get("icon");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment