feat: store UTM params in cookies, inject into webhook payloads

This commit is contained in:
ODOO4projects Web Developer committed 2026-10-05 20:30:30 +00:00
1 parent d83d960543
commit 5f4c75e94f
1 file changed
+58 -3
+58 -3
View File
@@ -6,6 +6,61 @@ var si = 0,
autoStop = false,
autoInterval = 7000;
/* ---- UTM tracking helpers ---- */
(function () {
function getCookie(name) {
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match ? decodeURIComponent(match[2]) : null;
}
function setCookie(name, value, days) {
var expires = '';
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toUTCString();
}
document.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/; SameSite=Lax';
}
function parseUTM() {
var urlParams = new URLSearchParams(window.location.search);
var utm = {};
var keys = ['source', 'medium', 'campaign'];
for (var i = 0; i < keys.length; i++) {
var val = urlParams.get('utm_' + keys[i]);
if (val) {
utm[keys[i]] = val;
setCookie('utm_' + keys[i], val, 90);
}
}
return utm;
}
function getStoredUTM() {
var utm = {};
var keys = ['source', 'medium', 'campaign'];
for (var i = 0; i < keys.length; i++) {
var val = getCookie('utm_' + keys[i]);
if (val) utm[keys[i]] = val;
}
return utm;
}
function injectUTM(data) {
var stored = getStoredUTM();
if (Object.keys(stored).length > 0) {
data.utm_source = stored.source || null;
data.utm_medium = stored.medium || null;
data.utm_campaign = stored.campaign || null;
}
return data;
}
window.UTM = { parse: parseUTM, getStored: getStoredUTM, inject: injectUTM };
window.UTM.parse(); // Parse on page load
})();
if (slides.length > 0 && dots.length > 0) {
function show(i, direction) {
if (direction === undefined) return;
@@ -505,7 +560,7 @@ var si = 0,
fetch('https://n8n.odoo4projects.com/webhook/ODOO4projects/trial', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: email, location: location })
body: JSON.stringify(UTM.inject({ email: email, location: location }))
}).then(function() {
trialForm.style.display = 'none';
document.getElementById('trialSuccess').classList.add('visible');
@@ -609,7 +664,7 @@ var si = 0,
fetch('https://n8n.odoo4projects.com/webhook/bring-your-business', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
body: JSON.stringify(UTM.inject({
email: email,
description: description,
goals: goals,
@@ -617,7 +672,7 @@ var si = 0,
has_homepage: hasHomepage,
uses_odoo: usesOdoo,
has_developer: hasDeveloper
})
}))
}).catch(function () { /* ignore */ });
/* Show success message — we'll email the report */