l
This commit is contained in:
+106
-97
@@ -1,52 +1,59 @@
|
||||
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 cookie value ---
|
||||
function getCookie(name) {
|
||||
const value = `; ${document.cookie}`;
|
||||
const parts = value.split(`; ${name}=`);
|
||||
if (parts.length === 2) return parts.pop().split(';').shift();
|
||||
return null;
|
||||
const value = `; ${document.cookie}`;
|
||||
const parts = value.split(`; ${name}=`);
|
||||
if (parts.length === 2) return parts.pop().split(";").shift();
|
||||
return null;
|
||||
}
|
||||
|
||||
// --- Add UTM fields to form ---
|
||||
function addUtmFields(form) {
|
||||
const utmParams = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
||||
const utmParams = [
|
||||
"utm_source",
|
||||
"utm_medium",
|
||||
"utm_campaign",
|
||||
"utm_term",
|
||||
"utm_content",
|
||||
];
|
||||
|
||||
const defaults = {
|
||||
utm_source: "homepage",
|
||||
utm_medium: "direct",
|
||||
utm_campaign: "none"
|
||||
};
|
||||
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);
|
||||
}
|
||||
const cookieValue = getCookie(param);
|
||||
input.value = cookieValue || defaults[param] || "";
|
||||
});
|
||||
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);
|
||||
}
|
||||
const cookieValue = getCookie(param);
|
||||
input.value = cookieValue || defaults[param] || "";
|
||||
});
|
||||
}
|
||||
|
||||
// --- Create modal ---
|
||||
function tryNow_createModal() {
|
||||
const modal = document.createElement("div");
|
||||
modal.id = "trynowModal";
|
||||
modal.style.position = "fixed";
|
||||
modal.style.top = "0";
|
||||
modal.style.left = "0";
|
||||
modal.style.width = "100%";
|
||||
modal.style.height = "100%";
|
||||
modal.style.backgroundColor = "rgba(0,0,0,0.6)";
|
||||
modal.style.display = "none";
|
||||
modal.style.justifyContent = "center";
|
||||
modal.style.alignItems = "center";
|
||||
modal.style.zIndex = "1000";
|
||||
const modal = document.createElement("div");
|
||||
modal.id = "trynowModal";
|
||||
modal.style.position = "fixed";
|
||||
modal.style.top = "0";
|
||||
modal.style.left = "0";
|
||||
modal.style.width = "100%";
|
||||
modal.style.height = "100%";
|
||||
modal.style.backgroundColor = "rgba(0,0,0,0.6)";
|
||||
modal.style.display = "none";
|
||||
modal.style.justifyContent = "center";
|
||||
modal.style.alignItems = "center";
|
||||
modal.style.zIndex = "1000";
|
||||
|
||||
modal.innerHTML = `
|
||||
modal.innerHTML = `
|
||||
<div style="
|
||||
background: #ffffff;
|
||||
padding: 40px 30px;
|
||||
@@ -84,7 +91,6 @@ function tryNow_createModal() {
|
||||
|
||||
<select name="product" required style="padding: 12px 15px; font-size: 16px; border: 1px solid #ccc; border-radius: 8px; outline: none;">
|
||||
<option value="odoo_19" selected>ODOO</option>
|
||||
<option value="N8N">n8n</option>
|
||||
</select>
|
||||
|
||||
<button type="submit" style="
|
||||
@@ -126,87 +132,90 @@ function tryNow_createModal() {
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.body.appendChild(modal);
|
||||
document.body.appendChild(modal);
|
||||
|
||||
// Add UTM fields after form exists
|
||||
const form = modal.querySelector("#trynowForm");
|
||||
addUtmFields(form);
|
||||
// Add UTM fields after form exists
|
||||
const form = modal.querySelector("#trynowForm");
|
||||
addUtmFields(form);
|
||||
|
||||
// Close modal handlers
|
||||
document.getElementById("trynowCloseModal").onclick = () => { modal.style.display = "none"; };
|
||||
document.getElementById("trynowCloseConfirmation").onclick = () => {
|
||||
document.getElementById("trynowConfirmation").style.display = "none";
|
||||
modal.style.display = "none";
|
||||
};
|
||||
modal.onclick = (e) => { if (e.target === modal) modal.style.display = "none"; };
|
||||
// Close modal handlers
|
||||
document.getElementById("trynowCloseModal").onclick = () => {
|
||||
modal.style.display = "none";
|
||||
};
|
||||
document.getElementById("trynowCloseConfirmation").onclick = () => {
|
||||
document.getElementById("trynowConfirmation").style.display = "none";
|
||||
modal.style.display = "none";
|
||||
};
|
||||
modal.onclick = (e) => {
|
||||
if (e.target === modal) modal.style.display = "none";
|
||||
};
|
||||
|
||||
return modal;
|
||||
return modal;
|
||||
}
|
||||
|
||||
// --- Handle form submission ---
|
||||
function tryNow_handleFormSubmit() {
|
||||
const form = document.getElementById("trynowForm");
|
||||
const confirmation = document.getElementById("trynowConfirmation");
|
||||
const form = document.getElementById("trynowForm");
|
||||
const confirmation = document.getElementById("trynowConfirmation");
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
// Update UTM fields from cookies
|
||||
addUtmFields(form);
|
||||
// Update UTM fields from cookies
|
||||
addUtmFields(form);
|
||||
|
||||
const data = {};
|
||||
new FormData(form).forEach((value, key) => (data[key] = value));
|
||||
const data = {};
|
||||
new FormData(form).forEach((value, key) => (data[key] = value));
|
||||
|
||||
try {
|
||||
const res = await fetch(TRYNOW_WEBHOOK_URL, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
try {
|
||||
const res = await fetch(TRYNOW_WEBHOOK_URL, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
form.style.display = "none";
|
||||
confirmation.style.display = "block";
|
||||
form.reset();
|
||||
} else {
|
||||
alert("Failed to submit form.");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
alert("Error submitting form.");
|
||||
}
|
||||
});
|
||||
if (res.ok) {
|
||||
form.style.display = "none";
|
||||
confirmation.style.display = "block";
|
||||
form.reset();
|
||||
} else {
|
||||
alert("Failed to submit form.");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
alert("Error submitting form.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// --- Attach "Try Now" buttons ---
|
||||
function tryNow_attachButtons() {
|
||||
const buttons = Array.from(document.querySelectorAll("a, button"));
|
||||
buttons.forEach(btn => {
|
||||
if (btn.textContent && btn.textContent.trim() === "Try Now") {
|
||||
btn.addEventListener("click", (e) => {
|
||||
e.preventDefault();
|
||||
const modal = document.getElementById("trynowModal");
|
||||
if (modal) {
|
||||
modal.style.display = "flex";
|
||||
const buttons = Array.from(document.querySelectorAll("a, button"));
|
||||
buttons.forEach((btn) => {
|
||||
if (btn.textContent && btn.textContent.trim() === "Try Now") {
|
||||
btn.addEventListener("click", (e) => {
|
||||
e.preventDefault();
|
||||
const modal = document.getElementById("trynowModal");
|
||||
if (modal) {
|
||||
modal.style.display = "flex";
|
||||
|
||||
// Reset modal state
|
||||
const form = document.getElementById("trynowForm");
|
||||
const confirmation = document.getElementById("trynowConfirmation");
|
||||
if (form && confirmation) {
|
||||
form.style.display = "flex";
|
||||
confirmation.style.display = "none";
|
||||
addUtmFields(form); // refresh UTM fields each open
|
||||
}
|
||||
}
|
||||
});
|
||||
// Reset modal state
|
||||
const form = document.getElementById("trynowForm");
|
||||
const confirmation = document.getElementById("trynowConfirmation");
|
||||
if (form && confirmation) {
|
||||
form.style.display = "flex";
|
||||
confirmation.style.display = "none";
|
||||
addUtmFields(form); // refresh UTM fields each open
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// --- Initialize ---
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
tryNow_createModal();
|
||||
tryNow_handleFormSubmit();
|
||||
tryNow_attachButtons();
|
||||
tryNow_createModal();
|
||||
tryNow_handleFormSubmit();
|
||||
tryNow_attachButtons();
|
||||
});
|
||||
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user