-
Notifications
You must be signed in to change notification settings - Fork 0
/
affiliate.html
46 lines (39 loc) · 1.26 KB
/
affiliate.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<html></html>
<script>
const getReferralAddress = () => {
const mangledCode = localStorage.getItem("znn-referral-code");
if (mangledCode) {
return mangledCode;
} else {
return "";
}
};
const setReferralCodeAddress = (mangledCode) => {
if (mangledCode) {
return localStorage.setItem("znn-referral-code", mangledCode);
} else {
throw "Unable to set referral code";
}
};
console.log("Setting affiliate code");
const urlParams = new URLSearchParams(window.location.search);
console.log("urlParams", urlParams);
const referralCode = urlParams.get("referral") || "";
console.log("referralCode", referralCode);
const originURL = urlParams.get("originURL") || "";
console.log("originURL", originURL);
if (referralCode) {
console.log("__New referral code detected", referralCode);
if (!getReferralAddress()?.length) {
console.log("__Using: ", referralCode);
setReferralCodeAddress(referralCode || "");
} else {
console.log("Detected existing referral code: ", getReferralAddress());
console.log("Using the existing one", getReferralAddress());
}
}
if (originURL?.length) {
console.log("__originURL", originURL);
window.location.replace(originURL);
}
</script>