Created
May 22, 2019 12:56
-
-
Save jaspreetsidhu/119de0a988cfca4edcb3488efac830cc to your computer and use it in GitHub Desktop.
Pardot Javascript UTM
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
<script type="text/javascript"> | |
// Parse the URL | |
function getParameterByName(name) { | |
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); | |
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), | |
results = regex.exec(location.search); | |
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); | |
} | |
// Give the URL parameters variable names | |
var source = getParameterByName('utm_source'); | |
var medium = getParameterByName('utm_medium'); | |
var campaign = getParameterByName('utm_campaign'); | |
var term = getParameterByName('utm_term'); | |
var content = getParameterByName('utm_content'); | |
// Put the variable names into the hidden fields in the form. selector should be "p.YOURFIELDNAME input" | |
document.querySelector("p.source input").value = source; | |
document.querySelector("p.utm_medium input").value = medium; | |
document.querySelector("p.utm_campaign input").value = campaign; | |
document.querySelector("p.utm_term input").value = term; | |
document.querySelector("p.utm_content input").value = content; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment