I need to pass variable UTM parameters with form data to Salesforce. I don't have trouble passing other form field data to Salesforce via the form's Logic tab, but this part is a puzzle.
I've got an embedded MachForm in my client's website, so the URI needs to look outside of MachForm's iframe. (e.g. https://foo-client-website.org/?msclkid=f66ac82d9b5c1ab5405d9580257808b3&utm_source=bing&utm_medium=cpc&utm_campaign=National%20%7C%20Business%20Solutions&utm_term=%2Bbusiness%20%2Blogistics&utm_content=Business%20Solutions)
I've tried modifying Salesforce's provided script for this, so that it's looking for my MachForm field ID's, and I can just auto-fill the text fields with the parsed parameters.
But I'm having trouble knowing where/how to load this, or if it would be better to hack it into one of MachForm's files. (I've tried adding it to my outside HTML and calling it from within the MachForm properties, but I keep getting a "Cannot set property 'value' of null" error).
Any ideas, folks?
<script type="text/javascript">
function parseGET(param) {
var searchStr = document.location.search;
try {
var match = searchStr.match('[?&]' + param + '=([&]+)');
if (match) {
var result = match[1];
result = result.replace(/+/g, '%20');
result = decodeURIComponent(result);
return result;
} else {
return '';
}
} catch (e) {
return '';
}
}
document.getElementById('element_6').value = parseGET('utm_source');
document.getElementById('element_5').value = parseGET('utm_medium');
document.getElementById('element_4').value = parseGET('utm_campaign');
document.getElementById('element_7').value = parseGET('utm_term');
document.getElementById('element_4').value = parseGET('utm_content');
</script>