Overview
In order to send offline sales stats from Zoho CRM to Google Analytics, we need to know which lead/account/opportunity/booking belongs to which website visitor in Google Analytics.
This can be achieved by saving the ID of each website visitor to Zoho CRM during the form submission.
This ID (Google Analytics Client ID, or GA CID) should be saved to Zoho CRM Lead object, alongside the normal form submission data like phone, name or email address.
This ID normally looks like two long numbers separated by a dot, for example: 1233979415.1478058607
There are ways we can retrieve CID:
- Using JavaScript, by calling analytics.js methods.
- Server-side, by retrieving the cookie that contains CID.
- Use GA Connector (easiest method)
But before this, the first thing is to apply the Google Analytics Client ID field that came with the Google Analytics Extension as a hidden field in your Zoho Lead Form.
1. Go to Setup > Webforms and edit the form your want to integrate with GA Connector and Google Analytics.
2. Update the form by adding the Google Analytics Client ID Field to the form as a hidden field
3. Click Done and then Next Step. You will then be shown the Form Details page, no need to change those so just click Save.
Editing the code
1. What we need to get to is the Embed Options page where it will provide the Webform Source Code. No need to copy the entire code at all and we only need the input field for the hidden Google Analytics Client ID field we just added.
2. Copy this part only and add this to your form code you already have on your site and while on it, add a unique “id” attribute to the code, like below:
Take note of this ID as we will be using in the next steps.
Method #1 – Retrieving CID from JavaScript
Here is the code snippet that can be used to retrieve client ID as provided by Google outlined in their Developers Article.
1 2 3 |
ga(function(tracker) { var clientId = tracker.get('clientId'); }); |
This code only extracts the Google Analytics CID and in order for us to put that CID value to the hidden form field, we will need to add an additional string to the code above:
1 2 3 4 |
document.getElementById('XXXX').value = clientId; // change the ‘XXXX’ to the value of the id // attribute you have set in the hidden form |
So this will look like this:
1 2 3 4 5 6 7 |
ga(function(tracker) { var clientId = tracker.get('clientId'); document.getElementById('gaFieldID').value = clientId; }); // change the ‘gaFieldID’ to the value of the // id attribute you have set in the hidden form |
This code should be placed right before the closing </script> tag of the Google Analytics code, as it won’t work unless GA tracker is already initialized. See example below:
Method #2 – Retrieving CID on the server-side
Client ID is stored in browser cookies, which is why it can also be retrieved on the server-side.
The name of the cookie that contains CID is _ga:
The only problem is that _ga cookie contains some extra information except for GA CID itself.
Here is a sample value that is stored in _ga cookie: GA1.2.1233979415.1478058607
1233979415.1478058607 is the actual CID, while GA1.2. is just prefix that contains versioning number and cookie domain level.
We need to remove the prefix and only send the second half of the CID to Zoho CRM.
Here is the code example (in PHP) for retrieving CID on the sever-side:
1 2 3 |
<?php $cid = preg_replace('/GA[0-9]+\.[0-9]+\./', '', $_COOKIE['_ga']); ?> |
Method #3 – Using GA Connector (easiest method)
Aside from UTM parameters and tracking information, GA Connector also provides the easiest method to extract GA4 information on your website visitors.
While editing your form embed code, use the ID “GA_Client_ID” so the code will be:
<input id=”GA_Client_ID”…>
That’s it! No more additional custom scripts. GA Connector will automatically fill up this field with the GA Client ID.
For a full list of data that you can track with GA Connector, check out this article.