I am using the following code in tag manager for the page in question. You would need to change your form id obviously,embed the form in RAW HTML and make sure the field is hidden. Then I have a zapier integration to connect the offline connection and form submission.
Hope it helps!
<script>
function getParam(p, url) {
var match = RegExp(‘[?&]’ + p + ‘=([^&]*)’).exec(url);
return match && decodeURIComponent(match[1].replace(/\+/g, ’ '));
}
function setCookie(name, value, days) {
var expires = “”;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = “; expires=” + date.toUTCString();
}
document.cookie = name + “=” + (value || “”) + expires + “; path=/”;
}
function getCookie(name) {
var nameEQ = name + “=”;
var ca = document.cookie.split(‘;’);
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ’ ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function addGclidToForm() {
var hubspotForm = document.getElementById(‘hsForm_22c4644f-8001-4f91-a34a-3b16a8e2c551’);
if (hubspotForm) {
var gclid = getCookie(‘gclid’);
if (gclid) {
var gclidInput = document.createElement(‘input’);
gclidInput.type = ‘hidden’;
gclidInput.name = ‘gclid’;
gclidInput.value = gclid;
hubspotForm.appendChild(gclidInput);
}
clearInterval(checkFormInterval);
}
}
var currentUrl = document.location.href;
var gclidParam = getParam(‘gclid’, currentUrl);
var gclsrcParam = getParam(‘gclsrc’, currentUrl);
var isGclsrcValid = !gclsrcParam || gclsrcParam.indexOf(‘aw’) !== -1;
if (gclidParam && isGclsrcValid) {
setCookie(‘gclid’, gclidParam, 90); // 90 day expiry
}
// Check for the form’s presence every 500 milliseconds
var checkFormInterval = setInterval(addGclidToForm, 500);
</script>