Last active
July 1, 2023 15:40
-
-
Save ceaksan/2116c33c3644f7158c9f65fedd2a0540 to your computer and use it in GitHub Desktop.
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
(function () { | |
var urlParams = new URLSearchParams(window.location.search); | |
var paramsToAppend = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'ref', '_gl']; | |
var formButton = document.querySelector('.button_class'); | |
if (formButton) { | |
var dataUrl = formButton.getAttribute('data-url'); | |
if (dataUrl) { | |
var url = new URL(dataUrl); | |
paramsToAppend.forEach(function (param) { | |
if (urlParams.has(param)) { | |
url.searchParams.set(param, urlParams.get(param)); | |
} | |
}); | |
formButton.setAttribute('data-url', url.toString()); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment