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:

  1. Either using JavaScript, by calling analytics.js methods.
  2. Or on the server-side, by simply retrieving the cookie that contains CID.

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

Google Analytics Client ID Field

Google Analytics Client ID Field hidden

 

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.

Webform Source Code

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:

Input Google Analytics Client ID

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.

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:

So this will look like this:

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:

Google Analytics Script

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 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:

The JavaScript method is more preferable, as:

You should not directly access the cookie analytics.js sets, as the cookie format might change in the future (from analytics.js documentation).

But not to worry, the server-side cookie method has been working for a long long time and will probably keep working for a long-long time. gaconnector.com website relies on this method too.