Skip to content

Instantly share code, notes, and snippets.

@cougrimes
Last active August 29, 2015 14:13
Show Gist options
  • Save cougrimes/1cff746d9beb19da267f to your computer and use it in GitHub Desktop.
Save cougrimes/1cff746d9beb19da267f to your computer and use it in GitHub Desktop.
Parse Google Analytics parameters as JS variables
var getURLParams = function() {
var temp = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function() {
var decode = function(s) {
return decodeURIComponent(s.split("+").join(" "));
};
temp[decode(arguments[1])] = decode(arguments[2]);
});
return temp;
};
var $_GET = getURLParams();
var utmMedium = getURLParams()["utm_medium"];
var utmSource = getURLParams()["utm_source"];
var utmCampaign = getURLParams()["utm_campaign"];
var utmTerm = getURLParams()["utm_term"];
var utmContent = getURLParams()["utm_content"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment