Skip to content

Instantly share code, notes, and snippets.

@SoerenS
Created June 11, 2015 14:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SoerenS/94529bc2b87667727ca3 to your computer and use it in GitHub Desktop.
Save SoerenS/94529bc2b87667727ca3 to your computer and use it in GitHub Desktop.
JS Bookmarklet to add Analytics Tracking parameters to an URL
javascript:(function moo() {
var utm = "utm_source=facebook&utm_medium=social&utm_campaign=XXX";
var d = new Date();
var url = document.location.href;
utm += (""+d.getFullYear()).slice(-2) + ("0"+(d.getMonth()+1)).slice(-2) + ("0"+(d.getDay()+1)).slice(-2) + ("0"+(d.getHours()+1)).slice(-2) + ("0"+(d.getMinutes()+1)).slice(-2);
if (document.location.href.indexOf('#')>-1 && !document.location.href.indexOf('?')>-1){ url = url.replace("#", "?"+utm+"#"); }
else if (document.location.href.indexOf('#')>-1 && document.location.href.indexOf('?')>-1){ url = url.replace("#", "&"+utm+"#"); }
else if (document.location.href.indexOf('?')>-1){ url += "&" + utm; }
else{ url += "?" + utm; }
document.location.href = url;
return false;})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment