-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (29 loc) · 805 Bytes
/
Copy pathscript.js
File metadata and controls
32 lines (29 loc) · 805 Bytes
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
// Utility to get query params
function getParam(param) {
return new URLSearchParams(window.location.search).get(param);
}
// Read values from URL
const customerId = getParam("cid");
const name = getParam("name");
// Personalize UI
if (name) {
document.getElementById("headline").innerText = `Hey ${name} 👋`;
document.getElementById("subtext").innerText =
"Thanks for checking out this personalized page.";
}
// Log visit (ONLY ONCE PER SESSION)
if (customerId && name) {
fetch("http://localhost:3000/track", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
customerId,
name,
page: window.location.pathname,
userAgent: navigator.userAgent,
timestamp: new Date().toISOString(),
}),
});
}