{"id":597,"date":"2017-08-23T16:55:49","date_gmt":"2017-08-23T16:55:49","guid":{"rendered":"http:\/\/support.gaconnector.com\/?p=597"},"modified":"2025-08-11T15:54:49","modified_gmt":"2025-08-11T15:54:49","slug":"save-google-analytics-client-id-cookie-to-zoho-crm","status":"publish","type":"post","link":"https:\/\/gaconnector.com\/docs\/save-google-analytics-client-id-cookie-to-zoho-crm\/","title":{"rendered":"Save Google Analytics Client ID and Session ID to Zoho CRM"},"content":{"rendered":"<h2>Overview<\/h2>\n<p>In order to send offline sales stats from Zoho CRM\u00a0to Google Analytics, we need to know which lead\/account\/opportunity\/booking belongs to which website visitor in Google Analytics.<\/p>\n<p>This can be achieved by saving the ID of each website visitor to Zoho CRM\u00a0during the form submission.<\/p>\n<p>This ID (Google Analytics Client ID, or GA CID) should be saved to Zoho CRM\u00a0Lead object,\u00a0alongside the normal form submission data like phone, name or email address.<\/p>\n<p>This ID normally looks like two long numbers separated by a dot, for example:\u00a0<em>1233979415.1478058607<\/em><\/p>\n<p>There are ways we can retrieve CID:<\/p>\n<ol>\n<li>Using JavaScript, by calling gtag.js methods.<\/li>\n<li>Server-side, by retrieving the cookie that contains CID.<\/li>\n<li>Use GA Connector (easiest method)<\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">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.<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">1. Go to <strong>Setup<\/strong> &gt; <strong>Webforms<\/strong> and edit the form your want to integrate with GA Connector and Google Analytics. <\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">2. Update the form by adding the Google Analytics Client ID Field to the form as a hidden field<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/gaconnector.com\/docs\/wp-content\/uploads\/2018\/07\/pasted-image-01.png\" alt=\"Google Analytics Client ID Field\" width=\"833\" height=\"443\" \/><\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/gaconnector.com\/docs\/wp-content\/uploads\/2018\/07\/pasted-image-02.png\" alt=\"Google Analytics Client ID Field hidden\" width=\"415\" height=\"319\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">3.\u00a0<span class=\"c20\">Click <strong>Done<\/strong> and then <strong>Next Step<\/strong>. You will then be shown the Form Details page, no need to change those \u00a0so just click\u00a0<\/span><span class=\"c11\"><strong>Save<\/strong>.<\/span><\/p>\n<h2>Editing the code<\/h2>\n<p style=\"padding-left: 30px;\">1.\u00a0What 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.<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/gaconnector.com\/docs\/wp-content\/uploads\/2018\/07\/pasted-image-03.png\" alt=\"Webform Source Code\" width=\"641\" height=\"479\" \/><\/p>\n<p style=\"padding-left: 30px;\">2.\u00a0Copy this part only and add this to your form code you already have on your site and while on it, add a unique \u201cid\u201d attribute to the code, like below:<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/gaconnector.com\/docs\/wp-content\/uploads\/2018\/07\/pasted-image-04.png\" alt=\"Input Google Analytics Client ID\" width=\"838\" height=\"145\" \/><\/p>\n<p style=\"padding-left: 30px;\">Take note of this ID as we will be using in the next steps.<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Method #1 &#8211; Retrieving\u00a0CID from JavaScript<\/strong><\/h2>\n<p><span class=\"c20\">Here is the code snippet that can be used to retrieve client ID as provided by Google outlined in their\u00a0<\/span><span class=\"c16\"><a class=\"c24\" href=\"https:\/\/www.google.com\/url?q=https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/cookies-user-id%23getting_the_client_id_from_the_cookie&amp;sa=D&amp;ust=1505820034286000&amp;usg=AFQjCNG297GX0anTt9Kdv3Daw8WGyOTYJA\">Developers Article<\/a><\/span><span class=\"c4\">.<\/span><\/p>\n<pre class=\"lang:default decode:true\">gtag('get', 'YOUR MEASUREMENT ID', 'client_id', (clientID) =&gt; {\r\nconsole.log(clientID)\r\n});\r\n\/\/ change the 'YOUR MEASUREMENT ID' with your GA4 property's measurement ID<\/pre>\n<p>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:<\/p>\n<pre class=\"expand:true lang:default decode:true\">document.getElementById('XXXX').value = clientID;\r\n\r\n\/\/ change the \u2018XXXX\u2019 to the value of the id attribute you have set in the hidden form<\/pre>\n<p>So this will look like this:<\/p>\n<pre class=\"lang:default decode:true\">gtag('get', 'YOUR MEASUREMENT ID', 'client_id', (clientID) =&gt; {\r\n    document.getElementById('XXXX').value = clientID;\r\n});\r\n\r\n\/\/ change the 'YOUR MEASUREMENT ID' with your GA4 property's measurement ID\r\n\/\/ change the \u2018XXXX\u2019 to the value of the id attribute you have set in the hidden form<\/pre>\n<p>This code should be placed right before the closing <strong>&lt;\/script&gt;<\/strong> tag of the Google Analytics code, as it won\u2019t work unless GA tracker is already initialized.<\/p>\n<h2><strong><br \/>\nMethod #2 &#8211; Retrieving\u00a0CID on the server-side<\/strong><\/h2>\n<p>Client ID is stored in browser cookies, which is why it can also be retrieved on the server-side.<\/p>\n<p>The name of the cookie that contains CID is\u00a0<em>_ga:<\/em><\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/gaconnector.com\/docs\/wp-content\/uploads\/2018\/07\/06.png\" alt=\"The name of the cookie that contains CID is _ga\" width=\"640\" height=\"162\" \/><\/p>\n<p>The only problem is that _ga cookie contains some extra information except for GA CID itself.<\/p>\n<p>Here is a sample value that is stored in _ga cookie:\u00a0<em>GA1.2.1233979415.1478058607<\/em><\/p>\n<p>1233979415.1478058607 is the actual CID, while\u00a0<em>GA1.2.<\/em>\u00a0is just prefix that contains versioning number and cookie domain level.<\/p>\n<p>We need to remove the prefix and only send the second half of the CID to Zoho CRM.<\/p>\n<p>Here is the code example (in PHP) for retrieving CID on the sever-side:<\/p>\n<pre class=\"lang:default decode:true\">&lt;?php\r\n$cid = preg_replace('\/GA[0-9]+\\.[0-9]+\\.\/', '', $_COOKIE['_ga']);\r\n?&gt;<\/pre>\n<h2><strong>Method #3 &#8211; Using GA Connector (easiest method)<\/strong><\/h2>\n<p>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.<\/p>\n<ol>\n<li>While editing your form embed code, use the ID &#8220;<strong>GA_Client_ID&#8221;\u00a0<\/strong>so the code will be:\n<p><em>&lt;input<strong> id=&#8221;GA_Client_ID&#8221;.<\/strong>..&gt;<\/em><\/li>\n<\/ol>\n<p>That&#8217;s it! No more additional custom scripts. GA Connector will automatically fill up this field with the GA Client ID.<\/p>\n<p>For a full list of data that you can track with GA Connector, check out this <a href=\"https:\/\/gaconnector.com\/docs\/ga-connector-field-codes\/\">article<\/a>.<\/p>\n<h2><strong>Saving the Session ID<\/strong><\/h2>\n<p data-start=\"221\" data-end=\"467\">To ensure GA4 correctly groups events into the same user session, you need to send the <strong data-start=\"308\" data-end=\"322\">Session ID<\/strong> along with the <strong data-start=\"338\" data-end=\"351\">Client ID<\/strong>.<br \/>\n<br data-start=\"352\" data-end=\"355\" \/>If you don\u2019t send the Session ID, events may appear as <strong data-start=\"410\" data-end=\"426\">&#8220;unassigned&#8221;<\/strong> in session-scoped dimensions within GA4.<\/p>\n<p data-start=\"469\" data-end=\"552\">With <strong data-start=\"474\" data-end=\"490\">GA Connector<\/strong>, you can capture and send the Session ID in just a few steps:<\/p>\n<ol>\n<li data-start=\"574\" data-end=\"744\">\n<p data-start=\"577\" data-end=\"614\"><strong data-start=\"577\" data-end=\"614\">Open Your Webform in GA Connector<\/strong><\/p>\n<ul data-start=\"618\" data-end=\"744\">\n<li data-start=\"618\" data-end=\"663\">\n<p data-start=\"620\" data-end=\"663\">Go to <strong data-start=\"626\" data-end=\"646\">Setup \u2192 Webforms<\/strong> in Zoho CRM.<\/p>\n<\/li>\n<li data-start=\"618\" data-end=\"663\">\n<p data-start=\"620\" data-end=\"663\">Edit the form you want to integrate with GA Connector and Google Analytics.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li data-start=\"746\" data-end=\"929\">\n<p data-start=\"749\" data-end=\"775\"><strong data-start=\"749\" data-end=\"775\">Add the GA4 Session ID<\/strong><\/p>\n<ul data-start=\"779\" data-end=\"929\">\n<li data-start=\"779\" data-end=\"929\">\n<p data-start=\"781\" data-end=\"929\">Similar to how you added the <strong data-start=\"810\" data-end=\"823\">Client ID<\/strong>, insert the <strong data-start=\"836\" data-end=\"867\">Google Analytics Session ID<\/strong> provided by the GA Connector extension you installed earlier.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li data-start=\"931\" data-end=\"1133\">\n<p data-start=\"934\" data-end=\"972\"><strong data-start=\"934\" data-end=\"972\">Update Your Website\u2019s Webform Code<\/strong><\/p>\n<ul data-start=\"976\" data-end=\"1133\">\n<li data-start=\"976\" data-end=\"1040\">\n<p data-start=\"978\" data-end=\"1040\">Locate the input field for the Session ID that you just added.<\/p>\n<\/li>\n<li data-start=\"1044\" data-end=\"1133\">\n<p data-start=\"1046\" data-end=\"1075\">Change its id attribute to: &lt;input id=&#8221;GA_Session_ID&#8221; &#8230;&gt;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li data-start=\"1044\" data-end=\"1133\">\n<p data-start=\"1046\" data-end=\"1075\"><strong data-start=\"1138\" data-end=\"1155\">Save and Test<\/strong><\/p>\n<ul data-start=\"1159\" data-end=\"1268\">\n<li data-start=\"1159\" data-end=\"1179\">\n<p data-start=\"1161\" data-end=\"1179\">Save your changes.<\/p>\n<\/li>\n<li data-start=\"1183\" data-end=\"1268\">\n<p data-start=\"1185\" data-end=\"1268\">Submit a test form and check that the Session ID is being captured and sent to GA4.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p data-start=\"1185\" data-end=\"1268\"><strong data-start=\"1277\" data-end=\"1291\">That\u2019s it!<\/strong> Your events will now include the Session ID, allowing GA4 to correctly attribute them to the right sessions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview In order to send offline sales stats from Zoho CRM\u00a0to 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\u00a0during the form submission. This ID (Google Analytics Client ID, or GA CID) should [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"_links":{"self":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/597"}],"collection":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/comments?post=597"}],"version-history":[{"count":24,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/597\/revisions"}],"predecessor-version":[{"id":3689,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/597\/revisions\/3689"}],"wp:attachment":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/media?parent=597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/categories?post=597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/tags?post=597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}