Created
September 15, 2016 18:43
-
-
Save brettkobo/35909ed12f821bc4042babefcfaf688e to your computer and use it in GitHub Desktop.
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"> | |
// pulls the value out of the parameter from a URL | |
function getParameterByName(name) { | |
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); | |
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), | |
results = regex.exec(location.search); | |
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); | |
} | |
try{ | |
// sets all of the UTM parameter | |
var utmSource = getParameterByName('utm_source'); | |
var utmMedium = getParameterByName('utm_medium'); | |
var utmCampaign = getParameterByName('utm_campaign'); | |
var utmContent = getParameterByName('utm_content'); | |
var utmTerm = getParameterByName('utm_term'); | |
if (utmSource) sessionStorage.setItem("utm_source", utmSource); | |
if (utmMedium) sessionStorage.setItem("utm_medium", utmMedium); | |
if (utmCampaign) sessionStorage.setItem("utm_campaign", utmCampaign); | |
if (utmContent) sessionStorage.setItem("utm_content", utmContent); | |
if (utmTerm) sessionStorage.setItem("utm_term", utmTerm); | |
} | |
catch (e) {} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment