From 5f4c75e94f0c33df37ac7a978a144de95c6cf53d Mon Sep 17 00:00:00 2001 From: ODOO4projects Web Developer Date: Mon, 5 Oct 2026 20:30:30 +0000 Subject: [PATCH] feat: store UTM params in cookies, inject into webhook payloads --- script.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 79795de..bb1f63c 100644 --- a/script.js +++ b/script.js @@ -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 */