Skip to content

Instantly share code, notes, and snippets.

@eyalway2cu
Created August 14, 2018 17:31
Show Gist options
  • Select an option

  • Save eyalway2cu/28945a3d6457681d64786152666d5130 to your computer and use it in GitHub Desktop.

Select an option

Save eyalway2cu/28945a3d6457681d64786152666d5130 to your computer and use it in GitHub Desktop.
Parse url as search
// Function to parse string as URL as used in Zapier
function getParameterByName (name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name.toLowerCase() + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(input.location.toLowerCase());
if (results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
if (getParameterByName("utm_source")){
var source = getParameterByName("utm_source");
}else{
var source = "no source";
}
if (getParameterByName("utm_medium")){
var medium = getParameterByName("utm_medium");
}else{
var medium = "no medium";
}
output = [{source: source, medium: medium}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment