defaults
This commit is contained in:
@@ -7,16 +7,24 @@ const CATEGORY_CONFIG = {
|
|||||||
// Add more categories as needed
|
// Add more categories as needed
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// --- Get URL parameters as an object ---
|
// --- Get URL parameters as an object ---
|
||||||
function getUrlParams() {
|
function getUrlParams() {
|
||||||
return Object.fromEntries(new URLSearchParams(window.location.search).entries());
|
return Object.fromEntries(new URLSearchParams(window.location.search).entries());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Add UTM fields to form ---
|
// --- Add UTM fields to form with defaults ---
|
||||||
function addUtmFields(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 urlParams = getUrlParams();
|
const urlParams = getUrlParams();
|
||||||
|
|
||||||
|
// Define default values
|
||||||
|
const defaults = {
|
||||||
|
utm_source: "homepage",
|
||||||
|
utm_medium: "direct",
|
||||||
|
utm_campaign: "none"
|
||||||
|
};
|
||||||
|
|
||||||
utmParams.forEach(param => {
|
utmParams.forEach(param => {
|
||||||
let input = form.querySelector(`input[name="${param}"]`);
|
let input = form.querySelector(`input[name="${param}"]`);
|
||||||
if (!input) {
|
if (!input) {
|
||||||
@@ -25,7 +33,8 @@ function addUtmFields(form) {
|
|||||||
input.name = param;
|
input.name = param;
|
||||||
form.appendChild(input);
|
form.appendChild(input);
|
||||||
}
|
}
|
||||||
input.value = urlParams[param] || "";
|
// Use URL param if exists, otherwise fallback to default, else empty string
|
||||||
|
input.value = urlParams[param] || defaults[param] || "";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
public/buyModal.min.js
vendored
2
public/buyModal.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user