This commit is contained in:
Oliver
2025-10-08 07:44:41 -03:00
parent e201366360
commit 32a3abaacb
2 changed files with 12 additions and 3 deletions

View File

@@ -7,16 +7,24 @@ const CATEGORY_CONFIG = {
// Add more categories as needed
};
// --- Get URL parameters as an object ---
function getUrlParams() {
return Object.fromEntries(new URLSearchParams(window.location.search).entries());
}
// --- Add UTM fields to form ---
// --- Add UTM fields to form with defaults ---
function addUtmFields(form) {
const utmParams = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
const urlParams = getUrlParams();
// Define default values
const defaults = {
utm_source: "homepage",
utm_medium: "direct",
utm_campaign: "none"
};
utmParams.forEach(param => {
let input = form.querySelector(`input[name="${param}"]`);
if (!input) {
@@ -25,7 +33,8 @@ function addUtmFields(form) {
input.name = param;
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] || "";
});
}