{"id":789,"date":"2017-09-14T15:06:21","date_gmt":"2017-09-14T15:06:21","guid":{"rendered":"http:\/\/support.gaconnector.com\/?p=789"},"modified":"2021-01-28T01:09:17","modified_gmt":"2021-01-28T01:09:17","slug":"how-to-configure-pardot-to-save-ga-client-id-to-salesforce","status":"publish","type":"post","link":"https:\/\/gaconnector.com\/docs\/how-to-configure-pardot-to-save-ga-client-id-to-salesforce\/","title":{"rendered":"How to configure Pardot to save GA Client ID to Salesforce"},"content":{"rendered":"<p>In order for this instruction to work,\u00a0we need to save GA Client ID to all new Salesforce leads that Pardot creates.<\/p>\n<ol>\n<li>First, go to\u00a0<a href=\"https:\/\/pi.pardot.com\/form\/forms\">Pardot &#8211; Forms<\/a>.<\/li>\n<li>Select a form you want to add to GA Connector.<\/li>\n<li>Click &#8220;Edit form&#8221;.<\/li>\n<li>Click &#8220;Fields&#8221;\u00a0add a new field &#8211; GA_Client_ID field (it need to be synced with GA Client ID field from GA Connector package).<\/li>\n<li>Open &#8220;Look and Feel&#8221; and select &#8220;Below Form&#8221;.<\/li>\n<li>Click the &#8220;Code&#8221; symbol (<img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/i.gyazo.com\/e40d3710d0dea6cfda11e4e3285e0d2b.png\" alt=\"Source Code\" width=\"20\" height=\"21\" \/>)in the editor. This will allow\u00a0to paste\u00a0raw HTML code there.<\/li>\n<li>Paste this\u00a0code in\u00a0the editor:<\/li>\n<\/ol>\n<pre class=\"lang:default decode:true\">&lt;script&gt;\r\n  function receiveGaClientId(event)\r\n  {\r\n    if (event.origin.indexOf('your-domain.com') !== -1 &amp;&amp; typeof event.data === 'string') {\r\n      var cid = event.data;      \r\n      document.querySelector(\"p.GA_Client_ID input[type=hidden]\").value = cid;\r\n    }\r\n  }\r\n  window.addEventListener(\"message\", receiveGaClientId, false);\r\n&lt;\/script&gt;<\/pre>\n<p>This code allows Pardot iframes to receive GA CID cookie value from the parent window.<\/p>\n<p>Keep in mind that this code assumes that your client ID field is called &#8220;GA Client ID&#8221;, and therefore has a CSS class &#8220;GA_Client_ID&#8221;. If it&#8217;s called differently in your case, you can replace &#8220;GA_Client_ID&#8221; in the code with the unique CSS class of that field.<\/p>\n<p>Finally, paste this code on your website (on every page that contains Pardot forms):<\/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\nfunction getCID() {\r\n    var _ga = getCookie('_ga');\r\n    var gaObj = window[window.GoogleAnalyticsObject];\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 hasClass(element, klass) {\r\n    return (' ' + element.className + ' ').indexOf(' ' + klass+ ' ') &gt; -1;\r\n}\r\n\r\nfunction getPardotIframes(callback) {\r\n    var iframes = document.getElementsByTagName('iframe');\r\n    for (var i=0; i&lt;iframes.length; i++) {\r\n        callback(iframes[i]);\r\n        try {\r\n            var innerIframes = iframes[i].contentDocument.getElementsByTagName('iframe');\r\n            for (var j=0; j&lt;innerIframes.length; j++) {\r\n                callback(innerIframes[j]);\r\n            }\r\n        } catch (e) {}\r\n    }\r\n}\r\n\r\nfunction sendCidToIframe() {\r\n    try {\r\n        var cid = getCID();\r\n        if (typeof cid === 'undefined') return;\r\n\r\n        getPardotIframes(function(pardotIframe) {\r\n            pardotIframe.contentWindow.postMessage(cid, \"*\");\r\n        });\r\n    } catch (error) {\r\n        console.log(\"Pardot CID script error:\", error);\r\n    }\r\n}\r\n  \r\nsetInterval(sendCidToIframe, 1000); \r\n&lt;\/script&gt;<\/pre>\n<div>If your Pardot forms isn&#8217;t\u00a0hosted on go.pardot.com, you also need to add a class or an ID attribute &#8220;pardotform&#8221; to your Pardot iframe:<\/div>\n<div>\n<pre class=\"lang:default decode:true \">&lt;iframe id=\"pardotform\" ...&gt;<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In order for this instruction to work,\u00a0we need to save GA Client ID to all new Salesforce leads that Pardot creates. First, go to\u00a0Pardot &#8211; Forms. Select a form you want to add to GA Connector. Click &#8220;Edit form&#8221;. Click &#8220;Fields&#8221;\u00a0add a new field &#8211; GA_Client_ID field (it need to be synced with GA Client [&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\/789"}],"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=789"}],"version-history":[{"count":16,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/789\/revisions"}],"predecessor-version":[{"id":2708,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/789\/revisions\/2708"}],"wp:attachment":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/media?parent=789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/categories?post=789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/tags?post=789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}