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 gtag.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 4 |
gtag('get', 'YOUR MEASUREMENT ID', 'client_id', (clientID) => { console.log(clientID) }); // change the 'YOUR MEASUREMENT ID' with your GA4 property's measurement ID |
The code above 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 line of code:
1 2 3 |
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 |
gtag('get', 'YOUR MEASUREMENT ID', 'client_id', (clientID) => { document.getElementById('XXXX').value = clientID; }); // change the 'YOUR MEASUREMENT ID' with your GA4 property's measurement ID // change the ‘XXXX’ 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.
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. Just add the GA Connector script to your website.
- 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.
Saving the Session ID
To ensure GA4 correctly groups events into the same user session, you need to send the Session ID along with the Client ID.
If you don’t send the Session ID, events may appear as “unassigned” in session-scoped dimensions within GA4.
With GA Connector, you can capture and send the Session ID in just a few steps:
-
Open Your Webform in GA Connector
-
Go to Setup → Webforms in Zoho CRM.
-
Edit the form you want to integrate with GA Connector and Google Analytics.
-
-
Add the GA4 Session ID
-
Similar to how you added the Client ID, insert the Google Analytics Session ID provided by the GA Connector extension you installed earlier.
-
-
Update Your Website’s Webform Code
-
Locate the input field for the Session ID that you just added.
-
Change its id attribute to: <input id=”GA_Session_ID” …>
-
-
Save and Test
-
Save your changes.
-
Submit a test form and check that the Session ID is being captured and sent to GA4.
-
That’s it! Your events will now include the Session ID, allowing GA4 to correctly attribute them to the right sessions.