Test gclid
script type="text/javascript">
// Function to retrieve cookie value
function getCookie(name) {
let cookieArr = document.cookie.split(";");
for (let i = 0; i < cookieArr.length; i++) {
let cookiePair = cookieArr[i].split("=");
if (name == cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[1]);
}
}
return null;
}
// Listen for form submissions across the site
document.addEventListener('submit', function(event) {
// Check if the submitted form should send data to HubSpot
var form = event.target;
if (form.tagName.toLowerCase() === 'form') {
var gclid = getCookie('gclid');
// If gclid exists, add it to the data sent to HubSpot
if (gclid) {
// Create a new FormData object from the submitted form
var formData = new FormData(form);
formData.append('gclid', gclid);
// Log for testing to see if gclid is added
console.log('gclid added to form submission:', gclid);
// HubSpot forms automatically send data, so no need to modify the form submission process.
// The 'gclid' should now be automatically included in the data sent by the HubSpot plugin.
}
}
}, true);