defaults
This commit is contained in:
@@ -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] || "";
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user