Last active
July 15, 2020 03:16
-
-
Save mojowen/81f9c5f4518ded5d1024c02f447cc97a to your computer and use it in GitHub Desktop.
NVRD Experiment iframe
This file contains 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
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.5.3/iframeResizer.min.js"></script> | |
<iframe width="70%" height="1350" id="iframe1" src="" scrolling="no" style="overflow: hidden; height: 1350px;"></iframe> | |
<script> | |
function getUrlVars() { | |
var vars = {}; | |
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function ( | |
m, | |
key, | |
value | |
) { | |
vars[key] = value; | |
}); | |
return vars; | |
} | |
function fisherYates(array) { | |
var count = array.length, | |
randomnumber, | |
temp; | |
while (count) { | |
randomnumber = (Math.random() * count--) | 0; | |
temp = array[count]; | |
array[count] = array[randomnumber]; | |
array[randomnumber] = temp; | |
} | |
} | |
function pickTool(tools, picked) { | |
fisherYates(tools); | |
for (var i = 0; i < tools.length; i++) { | |
if ((picked || "").toLowerCase() === tools[i].name) return tools[i]; | |
} | |
return tools[Math.floor(Math.random() * tools.length)]; | |
} | |
function setIframeSrc() { | |
var source = getUrlVars()["source"] || "", | |
tools = [ | |
{ | |
name: "rockthevote", | |
url: | |
"https://register.rockthevote.com/registrants/new/?partner=26179&source=", | |
}, | |
{ | |
name: "turbovote", | |
url: "https://nvrd.turbovote.org/name?r=", | |
}, | |
{ | |
name: "vote.org", | |
url: "https://register.vote.org/?partner=915150&campaign=", | |
}, | |
{ | |
name: "register2vote", | |
url: | |
"https://register2vote.org/r2v-form.html?appUse=ext&appStyle=2&appBranding=true&org=nvrd&utm_custom=", | |
}, | |
], | |
tool = pickTool(tools, getUrlVars()["tool"]), | |
url = tool.url.replace(/\#038\;/g, "") + source; | |
// NOTE: WordPress sometimes escapes & in the source | |
// source urls to & - this fixes | |
var iframe1 = document.getElementById("iframe1"); | |
if (-1 == navigator.userAgent.indexOf("MSIE")) { | |
iframe1.src = url; | |
} else { | |
iframe1.location = url; | |
} | |
iFrameResize({ log: false, checkOrigin: false }); | |
if (typeof window["_gaq"] !== "undefined") { | |
window["_gaq"].push([ | |
"_trackEvent", | |
"RegistrationWidget-Initialize", | |
tool.name, | |
url, | |
]); | |
} | |
if (typeof window["ga"] !== "undefined") { | |
window["ga"]("send", { | |
hitType: "event", | |
eventCategory: "RegistrationWidget-Initialize", | |
eventAction: tool.name, | |
eventLabel: url, | |
}); | |
} | |
iframe1.onload = function () { | |
if (typeof window["_gaq"] !== "undefined") { | |
window["_gaq"].push([ | |
"_trackEvent", | |
"RegistrationWidget", | |
tool.name, | |
url, | |
]); | |
} | |
if (typeof window["ga"] !== "undefined") { | |
window["ga"]("send", { | |
hitType: "event", | |
eventCategory: "RegistrationWidget", | |
eventAction: tool.name, | |
eventLabel: url, | |
}); | |
} | |
this.onload = function () {}; | |
}; | |
} | |
setTimeout(setIframeSrc, 1); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment