Public Access
feat: store UTM params in cookies, inject into webhook payloads
This commit is contained in:
1 parent
d83d960543
commit
5f4c75e94f
1 file changed
+58
-3
@@ -6,6 +6,61 @@ var si = 0,
|
|||||||
autoStop = false,
|
autoStop = false,
|
||||||
autoInterval = 7000;
|
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) {
|
if (slides.length > 0 && dots.length > 0) {
|
||||||
function show(i, direction) {
|
function show(i, direction) {
|
||||||
if (direction === undefined) return;
|
if (direction === undefined) return;
|
||||||
@@ -505,7 +560,7 @@ var si = 0,
|
|||||||
fetch('https://n8n.odoo4projects.com/webhook/ODOO4projects/trial', {
|
fetch('https://n8n.odoo4projects.com/webhook/ODOO4projects/trial', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ email: email, location: location })
|
body: JSON.stringify(UTM.inject({ email: email, location: location }))
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
trialForm.style.display = 'none';
|
trialForm.style.display = 'none';
|
||||||
document.getElementById('trialSuccess').classList.add('visible');
|
document.getElementById('trialSuccess').classList.add('visible');
|
||||||
@@ -609,7 +664,7 @@ var si = 0,
|
|||||||
fetch('https://n8n.odoo4projects.com/webhook/bring-your-business', {
|
fetch('https://n8n.odoo4projects.com/webhook/bring-your-business', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(UTM.inject({
|
||||||
email: email,
|
email: email,
|
||||||
description: description,
|
description: description,
|
||||||
goals: goals,
|
goals: goals,
|
||||||
@@ -617,7 +672,7 @@ var si = 0,
|
|||||||
has_homepage: hasHomepage,
|
has_homepage: hasHomepage,
|
||||||
uses_odoo: usesOdoo,
|
uses_odoo: usesOdoo,
|
||||||
has_developer: hasDeveloper
|
has_developer: hasDeveloper
|
||||||
})
|
}))
|
||||||
}).catch(function () { /* ignore */ });
|
}).catch(function () { /* ignore */ });
|
||||||
|
|
||||||
/* Show success message — we'll email the report */
|
/* Show success message — we'll email the report */
|
||||||
|
|||||||
Reference in new issue
Block a user