Created
June 11, 2015 14:48
-
-
Save SoerenS/94529bc2b87667727ca3 to your computer and use it in GitHub Desktop.
JS Bookmarklet to add Analytics Tracking parameters to an URL
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
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