Skip to content

Instantly share code, notes, and snippets.

@dillansimmons
Last active August 16, 2017 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dillansimmons/c85eee39e3f484528912527c7766bd3b to your computer and use it in GitHub Desktop.
Save dillansimmons/c85eee39e3f484528912527c7766bd3b to your computer and use it in GitHub Desktop.
Parse URL values
// JS for grabbing utm params
var getRefQueryParam = 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;
};
// Get all the UTM parameters before the page finishes rendering
var utmParamQueryString = '',
utmParamQueryStringTrimmed = '',
utm_code = '';
(function() {
utm_code = getRefQueryParam("utm_code"); //Renders the value in url if it is present ie .com?utm_code=Charlie *renders 'Charlie'
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment