{"id":1203,"date":"2017-11-30T18:47:01","date_gmt":"2017-11-30T18:47:01","guid":{"rendered":"http:\/\/support.gaconnector.com\/?p=1203"},"modified":"2025-08-11T15:53:47","modified_gmt":"2025-08-11T15:53:47","slug":"how-to-configure-marketo-to-save-ga-client-id-to-salesforce","status":"publish","type":"post","link":"https:\/\/gaconnector.com\/docs\/how-to-configure-marketo-to-save-ga-client-id-to-salesforce\/","title":{"rendered":"How to configure Marketo to save GA Client ID and Session ID to Salesforce"},"content":{"rendered":"<p>1. Open Marketo and find Google Analytics Client ID field that Marketo should have brought from Salesforce. If it didn&#8217;t, follow\u00a0<a href=\"https:\/\/docs.marketo.com\/display\/public\/DOCS\/Add+an+Existing+Salesforce+Field+to+the+Marketo+Sync\">this instruction<\/a>\u00a0from Marketo.<\/p>\n<p>2.\u00a0Add this\u00a0field as\u00a0a hidden field to all your forms.<\/p>\n<p>3. Open one of the forms and located this hidden field. It should look something like this:<\/p>\n<pre class=\"lang:default decode:true\">&lt;div class=\"mktoFormRow\"&gt;\r\n  &lt;input type=\"hidden\" name=\"gacid\" class=\"mktoField mktoFieldDescriptor mktoFormCol\" value=\"\" style=\"margin-bottom: 10px;\"&gt;\r\n  &lt;div class=\"mktoClear\"&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>4. Locate the name attribute of this field. In this example, it&#8217;s &#8220;gacid&#8221;. But in your case, it could be called differently.<\/p>\n<p>5. Add this piece JavaScript code to the website (you may need to replace &#8220;gacid&#8221; with your GA CID input name on line #35):<\/p>\n<pre class=\"lang:default decode:true\">&lt;script&gt;\r\nfunction getCookie(cname) {\r\n    var name = cname + \"=\";\r\n    var ca = document.cookie.split(';');\r\n    for (var i = 0; i &lt; ca.length; i++) {\r\n        var c = ca[i];\r\n        while (c.charAt(0) == ' ') c = c.substring(1);\r\n        if (c.indexOf(name) == 0) {\r\n            return c.substring(name.length, c.length);\r\n        }\r\n    }\r\n    return \"\";\r\n}\r\n\r\nfunction getCID() {\r\n    var _ga = getCookie('_ga');\r\n    var gaObj = window[window.GoogleAnalyticsObject];\r\n\r\n    if (typeof gaObj !== 'undefined' &amp;&amp; typeof gaObj['getAll'] !== 'undefined') {\r\n        var tracker = gaObj.getAll()[0];\r\n        return tracker.get(\"clientId\");\r\n    } else if (typeof _ga === 'string' &amp;&amp; _ga.length &gt; 0) {\r\n        var cidArr = _ga.split('.');\r\n        return cidArr.slice(cidArr.length - 2, cidArr.length).join('.');\r\n    }\r\n}\r\n\r\nfunction setHiddenFieldWithCID() {\r\n    var cid = getCID();\r\n    if (typeof cid === 'undefined') {\r\n        setTimeout(function() {\r\n            setHiddenFieldWithCID(callback);\r\n        }, 500);\r\n    } else {\r\n        $('input[name=\"gacid\"], input#gacid').val(cid);\r\n    }\r\n}\r\nsetHiddenFieldWithCID();\r\nsetInterval(setHiddenFieldWithCID,1000);\r\n&lt;\/script&gt;<\/pre>\n<p>That&#8217;s it &#8211; now GA Client IDs should be automatically populated to the hidden fields, which will be synced with Salesforce.<\/p>\n<h2><strong>Using GA Connector<\/strong><\/h2>\n<p>Aside from UTM parameters and tracking information, GA Connector also provides the easiest method to extract GA Client ID of your website visitors. Just add the GA Connector script to your website.<\/p>\n<p>While editing your form embed code, use the ID \u201c<strong>GA_Client_ID\u201d\u00a0<\/strong>so the code will be:<\/p>\n<pre class=\"lang:default decode:true\">&lt;div class=\"mktoFormRow\"&gt;\r\n  &lt;input type=\"hidden\" name=\"gacid\" id=\u201dGA_Client_ID\u201d class=\"mktoField mktoFieldDescriptor mktoFormCol\" value=\"\" style=\"margin-bottom: 10px;\"&gt;\r\n  &lt;div class=\"mktoClear\"&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>That\u2019s 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\u00a0<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\u00a0<strong data-start=\"308\" data-end=\"322\">Session ID<\/strong>\u00a0along with the\u00a0<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\u00a0<strong data-start=\"410\" data-end=\"426\">\u201cunassigned\u201d<\/strong>\u00a0in session-scoped dimensions within GA4.<\/p>\n<p data-start=\"469\" data-end=\"552\">With\u00a0<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\">Add the Session ID to your form as a hidden field<\/p>\n<\/li>\n<li data-start=\"574\" data-end=\"744\">Add the ID <strong>&#8220;GA_Session_ID&#8221; <\/strong>to the hidden field.<\/li>\n<\/ol>\n<p data-start=\"1185\" data-end=\"1268\"><strong data-start=\"1277\" data-end=\"1291\">That\u2019s it!<\/strong>\u00a0Your events will now include the Session ID, allowing GA4 to correctly attribute them to the right sessions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Open Marketo and find Google Analytics Client ID field that Marketo should have brought from Salesforce. If it didn&#8217;t, follow\u00a0this instruction\u00a0from Marketo. 2.\u00a0Add this\u00a0field as\u00a0a hidden field to all your forms. 3. Open one of the forms and located this hidden field. It should look something like this: &lt;div class=&#8221;mktoFormRow&#8221;&gt; &lt;input type=&#8221;hidden&#8221; name=&#8221;gacid&#8221; class=&#8221;mktoField [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/1203"}],"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=1203"}],"version-history":[{"count":11,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/1203\/revisions"}],"predecessor-version":[{"id":3688,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/1203\/revisions\/3688"}],"wp:attachment":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/media?parent=1203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/categories?post=1203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/tags?post=1203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}