Created
January 29, 2023 14:13
-
-
Save olegdater/4015170423b92d76b750e0efb6184b38 to your computer and use it in GitHub Desktop.
Parse airtable link and put source attribute to it
This file contains hidden or 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
// put it to <header></header> inside <script></script> tag | |
// make sure we run it once the page loads | |
window.addEventListener('load', parseAirtableLinks) | |
function parseAirtableLinks() { | |
console.log('Parse links started...') | |
let urlParams = new URLSearchParams(window.location.search); | |
let leadSource = urlParams.get('source'); | |
if (!leadSource) { | |
leadSource = "unknown"; | |
} | |
let links = document.getElementsByTagName("a"); | |
for (let i = 0; i < links.length; i++) { | |
let link = links[i]; | |
let href = link.getAttribute("href"); | |
if (href.indexOf("source") === -1 && href.indexOf("airtable") !== -1) { | |
// inserting correct link per Airtable documentation | |
// https://support.airtable.com/docs/prefilling-a-form#h_01FMTKA71EF8EPG3S7P1K7704V | |
// 1) We prefill the form | |
// 2) We make sure it's hidden | |
link.setAttribute("href", href + "?prefill_Source=" + leadSource + "&hide_Source=true"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment