Last active
August 16, 2021 21:48
-
-
Save doublejosh/ca8484cca78b0a339abd5b8a6ce79734 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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