Created
March 18, 2019 23:45
-
-
Save MarkNijhof/fb6b0ff60331be3b698334e080b5eb63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function parseQueryString() { | |
if (location.href.indexOf("?") === -1) return; | |
var sets = location.href.split("?")[1].split("&"); | |
var source = "organic"; | |
var medium = ""; | |
var campaign = ""; | |
var content = ""; | |
for (var i = 0; i < sets.length; i++) { | |
var set = sets[i].split("="); | |
if (set.length > 1) { | |
switch(set[0]) { | |
case "fbclid": | |
source = "facebook"; | |
if (medium !== "") { | |
medium = "social"; | |
} | |
break; | |
case "gclid": | |
source = "google"; | |
if (medium !== "") { | |
medium = "organic"; | |
} | |
break; | |
case "utm_source": | |
source = set[1]; | |
break; | |
case "utm_medium": | |
medium = set[1]; | |
break; | |
case "utm_campaign": | |
campaign = set[1]; | |
break; | |
case "utm_content": | |
content = set[1]; | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
var sources = JSON.parse(localStorage.getItem("___smakassen_sources") || "[]"); | |
sources.push({ | |
date: now(), | |
source: source, | |
medium: medium, | |
campaign: campaign, | |
content: content, | |
queryString: location.href | |
}); | |
localStorage.setItem("___smakassen_sources", JSON.stringify(sources)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment