Last active
June 26, 2018 19:37
-
-
Save camshaft/acf8e9e0b4cc55812bd6 to your computer and use it in GitHub Desktop.
multiple google experiments
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 choose(id, cb) { | |
var i = document.createElement('iframe'); | |
i.setAttribute('sandbox', 'allow-scripts allow-same-origin'); | |
document.body.appendChild(i); | |
var win = i.contentWindow.window; | |
win.loaded = function() { | |
cb(cxApi.chooseVariation()); | |
}; | |
var doc = win.document; | |
doc.open(); | |
doc.write('<script src="//www.google-analytics.com/cx/api.js?experiment=' + id+ '"></script><script>window.loaded();</script>'); | |
doc.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anyone stumbles across this, just FYI that the above does not work in IE. I had to use
frame.src = 'javascript:window["contents"]';
to get it the content into the frame. My code ended up looking something like this: