Skip to content

Instantly share code, notes, and snippets.

@doublejosh
Last active August 16, 2021 21:48
Show Gist options
  • Save doublejosh/ca8484cca78b0a339abd5b8a6ce79734 to your computer and use it in GitHub Desktop.
Save doublejosh/ca8484cca78b0a339abd5b8a6ce79734 to your computer and use it in GitHub Desktop.
const fields = [{ name: "email", value: "" }];
const hiddenFields = [
{ name: "lists", value: "waitlist" },
{ name: "source", value: "twitter" },
{ name: "medium", value: "social" },
{ name: "campaign", value: "header" },
{ name: "campaign_type", value: "website" },
];
const urlParams = new URLSearchParams(window.location.search);
console.log(
fields.concat(hiddenFields).reduce(
(obj, field) =>
Object.assign({}, obj, {
[field.name]: urlParams.has(field.name)
? urlParams.get(field.name)
: field.value || "",
}),
{}
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment