Hi all,
Here’s a tricky one.
I’ve read a number of posts around passing hidden data through form submissions.
However, our objective is to pass through a Google Analytics ID in this form field.
The JS I’ve been provided to do this (with GTM already setup) is:
function getClientId (uaid) {
try {
var trackers = ga.getAll();
var i, len;
for (i = 0, len = trackers.length; i < len; i += 1) {
if (trackers[i].get(‘trackingId’) === uaid) {
return trackers[i].get(‘clientId’);
}
}
} catch (e) {}
return ‘false’;
}
// By waiting for “onload”, we give GA enough time to load up before trying to get the Client ID.
window.onload = function () {
// Once the page has completely loaded, this next line finds the hidden field and sets its value to the CID.
document.getElementById(“cid”).value = getClientId(‘UA-62895838-4’);
}
example GA code above
How do I attach this code to a hidden form field - so that it auto-populates the GA code into the form itself?
Thanks all,
Jordan
Have you read Wix Support own pages about using Google Analytics and Tracking ID?
https://support.wix.com/en/article/adding-your-google-analytics-tracking-id-to-your-wix-site
You do not need to add the code to each page of your site.
https://support.wix.com/en/marketing-tools-analytics/google-analytics
Also about using Google Tag Manager too.
https://support.wix.com/en/article/adding-your-google-tag-manager-account-id-to-your-wix-site
See more here - https://support.wix.com/en/marketing-tools-analytics/marketing-integrations-tracking
Also, you won’t be able to use that code above directly in your page code as Wix Corvid won’t recognise window.onload and document.getElementById as for starters Wix won’t let you have access to the DOM so you would have to look at putting it into a html component on your page and passing data to and from it if needed.
https://support.wix.com/en/article/corvid-working-with-the-html-element
https://www.wix.com/corvid/reference/$w.HtmlComponent.html
Thanks for replying - we have GA synced with Wix - however that is not our objective.
We aren’t looking for an integration.
Effectively what we want to do is:
- Create a hidden-form field
- Insert that JSS code into that form field
- Attribute a form field submission (First Name, Last name, email + (AND) the unique Google Analytics USER ID)
If we can’t use window.onload and document.getElementByld, what is our alternative?
Hello Jordan,
have you been able to solve this?
Thanks in advance.
Adam