utm
This commit is contained in:
@@ -1,5 +1,44 @@
|
|||||||
const TRYNOW_WEBHOOK_URL = "https://002-001-5dd6e535-4d1c-46bc-9bd9-42ad4bc5f082.odoo4projects.com/webhook/c25169c6-4234-4b47-8e74-612b9539da0a";
|
const TRYNOW_WEBHOOK_URL = "https://002-001-5dd6e535-4d1c-46bc-9bd9-42ad4bc5f082.odoo4projects.com/webhook/c25169c6-4234-4b47-8e74-612b9539da0a";
|
||||||
|
|
||||||
|
// --- Helper: Get URL parameters ---
|
||||||
|
function getUrlParams() {
|
||||||
|
const params = {};
|
||||||
|
window.location.search
|
||||||
|
.substring(1)
|
||||||
|
.split("&")
|
||||||
|
.forEach(pair => {
|
||||||
|
if (pair) {
|
||||||
|
const [key, value] = pair.split("=");
|
||||||
|
params[decodeURIComponent(key)] = decodeURIComponent(value || "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Add UTM fields to form ---
|
||||||
|
function addUtmFields(form) {
|
||||||
|
const utmParams = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
||||||
|
const urlParams = getUrlParams();
|
||||||
|
|
||||||
|
const defaults = {
|
||||||
|
utm_source: "homepage",
|
||||||
|
utm_medium: "direct",
|
||||||
|
utm_campaign: "none"
|
||||||
|
};
|
||||||
|
|
||||||
|
utmParams.forEach(param => {
|
||||||
|
let input = form.querySelector(`input[name="${param}"]`);
|
||||||
|
if (!input) {
|
||||||
|
input = document.createElement("input");
|
||||||
|
input.type = "hidden";
|
||||||
|
input.name = param;
|
||||||
|
form.appendChild(input);
|
||||||
|
}
|
||||||
|
input.value = urlParams[param] || defaults[param] || "";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Create modal ---
|
||||||
function tryNow_createModal() {
|
function tryNow_createModal() {
|
||||||
const modal = document.createElement("div");
|
const modal = document.createElement("div");
|
||||||
modal.id = "trynowModal";
|
modal.id = "trynowModal";
|
||||||
@@ -92,6 +131,10 @@ function tryNow_createModal() {
|
|||||||
|
|
||||||
document.body.appendChild(modal);
|
document.body.appendChild(modal);
|
||||||
|
|
||||||
|
// Add UTM fields after form exists
|
||||||
|
const form = modal.querySelector("#trynowForm");
|
||||||
|
addUtmFields(form);
|
||||||
|
|
||||||
// Close modal handlers
|
// Close modal handlers
|
||||||
document.getElementById("trynowCloseModal").onclick = () => { modal.style.display = "none"; };
|
document.getElementById("trynowCloseModal").onclick = () => { modal.style.display = "none"; };
|
||||||
document.getElementById("trynowCloseConfirmation").onclick = () => {
|
document.getElementById("trynowCloseConfirmation").onclick = () => {
|
||||||
@@ -103,12 +146,17 @@ function tryNow_createModal() {
|
|||||||
return modal;
|
return modal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Handle form submission ---
|
||||||
function tryNow_handleFormSubmit() {
|
function tryNow_handleFormSubmit() {
|
||||||
const form = document.getElementById("trynowForm");
|
const form = document.getElementById("trynowForm");
|
||||||
const confirmation = document.getElementById("trynowConfirmation");
|
const confirmation = document.getElementById("trynowConfirmation");
|
||||||
|
|
||||||
form.addEventListener("submit", async (e) => {
|
form.addEventListener("submit", async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
// Update UTM fields in case URL changed
|
||||||
|
addUtmFields(form);
|
||||||
|
|
||||||
const data = {};
|
const data = {};
|
||||||
new FormData(form).forEach((value, key) => (data[key] = value));
|
new FormData(form).forEach((value, key) => (data[key] = value));
|
||||||
|
|
||||||
@@ -133,6 +181,7 @@ function tryNow_handleFormSubmit() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Attach "Try Now" buttons ---
|
||||||
function tryNow_attachButtons() {
|
function tryNow_attachButtons() {
|
||||||
const buttons = Array.from(document.querySelectorAll("a, button"));
|
const buttons = Array.from(document.querySelectorAll("a, button"));
|
||||||
buttons.forEach(btn => {
|
buttons.forEach(btn => {
|
||||||
@@ -142,12 +191,14 @@ function tryNow_attachButtons() {
|
|||||||
const modal = document.getElementById("trynowModal");
|
const modal = document.getElementById("trynowModal");
|
||||||
if (modal) {
|
if (modal) {
|
||||||
modal.style.display = "flex";
|
modal.style.display = "flex";
|
||||||
|
|
||||||
// Reset modal state
|
// Reset modal state
|
||||||
const form = document.getElementById("trynowForm");
|
const form = document.getElementById("trynowForm");
|
||||||
const confirmation = document.getElementById("trynowConfirmation");
|
const confirmation = document.getElementById("trynowConfirmation");
|
||||||
if (form && confirmation) {
|
if (form && confirmation) {
|
||||||
form.style.display = "flex";
|
form.style.display = "flex";
|
||||||
confirmation.style.display = "none";
|
confirmation.style.display = "none";
|
||||||
|
addUtmFields(form); // refresh UTM fields each open
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -155,11 +206,10 @@ function tryNow_attachButtons() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Initialize ---
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
tryNow_createModal();
|
tryNow_createModal();
|
||||||
tryNow_handleFormSubmit();
|
tryNow_handleFormSubmit();
|
||||||
tryNow_attachButtons();
|
tryNow_attachButtons();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
public/tryModal.min.js
vendored
2
public/tryModal.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user