Skip to content

Commit

Permalink
Update utm_helper.js
Browse files Browse the repository at this point in the history
  • Loading branch information
shanjingheng committed Apr 12, 2024
1 parent e0ca4ce commit 63c554a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions docs/.vuepress/public/utm_helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
var script = document.createElement('script');
script.setAttribute('type','text/javascript');
script.setAttribute('src',"https://cdn.jsdelivr.net/npm/[email protected]/dist/browser.min.js");
document.getElementsByTagName('head')[0].appendChild(script);

function getUTMParametersAndSetCookie() {
var utmParameters = {};
var params = new URLSearchParams(window.location.search);
Expand All @@ -8,9 +13,14 @@ function getUTMParametersAndSetCookie() {
}
if (document.referrer) {
var referrerDomain = new URL(document.referrer).hostname;
utmParameters['referrer'] = referrerDomain
utmParameters['referrer'] = referrerDomain;
} else {
utmParameters['referrer'] = "direct"
utmParameters['referrer'] = "direct";
}
if (browser) {
uaInfo = browser()
utmParameters['browser'] = uaInfo.browser
utmParameters['device'] = uaInfo.device
}
var rootDomain = getRootDomain(document.domain);
var existingCookie = getCookieByName("utmParameters");
Expand Down Expand Up @@ -48,4 +58,4 @@ function setCookie(name, value, days, domain) {
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; domain=." + domain + "; path=/";
}

getUTMParametersAndSetCookie();
window.onload = getUTMParametersAndSetCookie;

0 comments on commit 63c554a

Please sign in to comment.