Public Access
UTM
This commit is contained in:
1 parent
575e3efece
commit
b4e0faa62e
2 files changed
+70
-3
No files matched your search
@@ -342,6 +342,41 @@
|
|||||||
powerhouse: 5,
|
powerhouse: 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ── UTM tracking (source / medium / campaign) ─────────────────────────────
|
||||||
|
const UTM_KEYS = ["source", "medium", "campaign"];
|
||||||
|
|
||||||
|
function getCookie(name) {
|
||||||
|
const match = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)"));
|
||||||
|
return match ? decodeURIComponent(match[2]) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCookie(name, value, days) {
|
||||||
|
const date = new Date();
|
||||||
|
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
||||||
|
document.cookie =
|
||||||
|
name + "=" + encodeURIComponent(value) +
|
||||||
|
"; expires=" + date.toUTCString() +
|
||||||
|
"; path=/; SameSite=Lax";
|
||||||
|
}
|
||||||
|
|
||||||
|
UTM_KEYS.forEach(function (key) {
|
||||||
|
const val = params.get("utm_" + key);
|
||||||
|
if (val) setCookie("utm_" + key, val, 90);
|
||||||
|
});
|
||||||
|
|
||||||
|
function appendUTM(form) {
|
||||||
|
UTM_KEYS.forEach(function (key) {
|
||||||
|
const val = getCookie("utm_" + key);
|
||||||
|
if (val) {
|
||||||
|
const input = document.createElement("input");
|
||||||
|
input.type = "hidden";
|
||||||
|
input.name = "utm_" + key;
|
||||||
|
input.value = val;
|
||||||
|
form.appendChild(input);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ── Buy handler ───────────────────────────────────────────────────────────
|
// ── Buy handler ───────────────────────────────────────────────────────────
|
||||||
function buyProduct(productId) {
|
function buyProduct(productId) {
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
@@ -369,6 +404,7 @@
|
|||||||
clear.name = "clear";
|
clear.name = "clear";
|
||||||
clear.value = "1";
|
clear.value = "1";
|
||||||
form.appendChild(clear);
|
form.appendChild(clear);
|
||||||
|
appendUTM(form);
|
||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
form.submit();
|
form.submit();
|
||||||
document.body.removeChild(form);
|
document.body.removeChild(form);
|
||||||
|
|||||||
@@ -57,7 +57,33 @@ var si = 0,
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.UTM = { parse: parseUTM, getStored: getStoredUTM, inject: injectUTM };
|
function appendToForm(form) {
|
||||||
|
var stored = getStoredUTM();
|
||||||
|
var keys = ['source', 'medium', 'campaign'];
|
||||||
|
for (var i = 0; i < keys.length; i++) {
|
||||||
|
if (stored[keys[i]]) {
|
||||||
|
var input = document.createElement('input');
|
||||||
|
input.type = 'hidden';
|
||||||
|
input.name = 'utm_' + keys[i];
|
||||||
|
input.value = stored[keys[i]];
|
||||||
|
form.appendChild(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toQuery() {
|
||||||
|
var stored = getStoredUTM();
|
||||||
|
var parts = [];
|
||||||
|
var keys = ['source', 'medium', 'campaign'];
|
||||||
|
for (var i = 0; i < keys.length; i++) {
|
||||||
|
if (stored[keys[i]]) {
|
||||||
|
parts.push('utm_' + keys[i] + '=' + encodeURIComponent(stored[keys[i]]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parts.join('&');
|
||||||
|
}
|
||||||
|
|
||||||
|
window.UTM = { parse: parseUTM, getStored: getStoredUTM, inject: injectUTM, appendToForm: appendToForm, toQuery: toQuery };
|
||||||
window.UTM.parse(); // Parse on page load
|
window.UTM.parse(); // Parse on page load
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@@ -196,13 +222,15 @@ var si = 0,
|
|||||||
yearlySave.style.display = "block";
|
yearlySave.style.display = "block";
|
||||||
var buyBtn = document.getElementById("orderBuyBtn");
|
var buyBtn = document.getElementById("orderBuyBtn");
|
||||||
var loc = document.getElementById("orderServerLocation").value;
|
var loc = document.getElementById("orderServerLocation").value;
|
||||||
|
var utmQuery = UTM.toQuery();
|
||||||
buyBtn.href =
|
buyBtn.href =
|
||||||
"/3/" +
|
"/3/" +
|
||||||
price.toFixed(2) +
|
price.toFixed(2) +
|
||||||
"/4/" +
|
"/4/" +
|
||||||
encodeURIComponent(plan) +
|
encodeURIComponent(plan) +
|
||||||
"?location=" +
|
"?location=" +
|
||||||
encodeURIComponent(loc);
|
encodeURIComponent(loc) +
|
||||||
|
(utmQuery ? "&" + utmQuery : "");
|
||||||
widget.style.display = "flex";
|
widget.style.display = "flex";
|
||||||
orderPopupShown = true;
|
orderPopupShown = true;
|
||||||
}
|
}
|
||||||
@@ -233,13 +261,15 @@ var si = 0,
|
|||||||
.trim();
|
.trim();
|
||||||
var price = parseFloat(priceText);
|
var price = parseFloat(priceText);
|
||||||
var loc = this.value;
|
var loc = this.value;
|
||||||
|
var utmQuery = UTM.toQuery();
|
||||||
document.getElementById("orderBuyBtn").href =
|
document.getElementById("orderBuyBtn").href =
|
||||||
"/3/" +
|
"/3/" +
|
||||||
price.toFixed(2) +
|
price.toFixed(2) +
|
||||||
"/4/" +
|
"/4/" +
|
||||||
encodeURIComponent(plan) +
|
encodeURIComponent(plan) +
|
||||||
"?location=" +
|
"?location=" +
|
||||||
encodeURIComponent(loc);
|
encodeURIComponent(loc) +
|
||||||
|
(utmQuery ? "&" + utmQuery : "");
|
||||||
});
|
});
|
||||||
function applyCoupon() {
|
function applyCoupon() {
|
||||||
var input = document.getElementById("orderCouponInput");
|
var input = document.getElementById("orderCouponInput");
|
||||||
@@ -719,6 +749,7 @@ var si = 0,
|
|||||||
clear.name = 'clear';
|
clear.name = 'clear';
|
||||||
clear.value = '1';
|
clear.value = '1';
|
||||||
form.appendChild(clear);
|
form.appendChild(clear);
|
||||||
|
UTM.appendToForm(form);
|
||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
form.submit();
|
form.submit();
|
||||||
document.body.removeChild(form);
|
document.body.removeChild(form);
|
||||||
|
|||||||
Reference in new issue
Block a user