{"id":455,"date":"2018-10-25T22:50:45","date_gmt":"2018-10-25T22:50:45","guid":{"rendered":"https:\/\/gaconnector.com\/blog\/?p=455"},"modified":"2022-10-17T06:05:32","modified_gmt":"2022-10-17T06:05:32","slug":"how-to-save-gclid-adwords-click-id-to-salesforce","status":"publish","type":"post","link":"https:\/\/gaconnector.com\/blog\/how-to-save-gclid-adwords-click-id-to-salesforce\/","title":{"rendered":"How to save GCLID (Adwords click ID) to Salesforce"},"content":{"rendered":"<p>Saving GCLID (Adwords click ID) to Salesforce is an essential part of <a href=\"https:\/\/gaconnector.com\/blog\/salesforce-and-google-adwords-connector\/\">Salesforce &amp; Adwords integration<\/a>. In this article, we&#8217;ll show you step-by-step how you can do this.<\/p>\n<h2>Step 1 &#8211; Make sure\u00a0that Adwords adds GCLID to ad URLs<\/h2>\n<p>All you need to do is <a href=\"https:\/\/support.google.com\/analytics\/answer\/2938246\">make sure that auto-tagging is enabled<\/a> for your Adwords account. In case it&#8217;s not, you can do so using these steps:<\/p>\n<ol>\n<li>Sign in to your\u00a0<a href=\"https:\/\/ads.google.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Google Ads account<\/a>.<\/li>\n<li>In the left page menu, click\u00a0<strong>Settings<\/strong>.<\/li>\n<li>Click\u00a0<strong>Account settings<\/strong>\u00a0along the top of the page.<\/li>\n<li>Click the Auto-tagging section.<\/li>\n<li>To enable auto-tagging, check the box next to \u201cTag the URL that people click through from my ad.\u201d<\/li>\n<li>Click\u00a0<strong>Save<\/strong>.<\/li>\n<\/ol>\n<h2>Step 2 &#8211;\u00a0Create GCLID fields in Salesforce<\/h2>\n<p>Create 4 GCLID fields in Salesforce: for Lead, Opportunity, Account and Contact objects. Feel free to skip objects you&#8217;re not using.<\/p>\n<p>Make sure to\u00a0create Text fields with Length=255. They should look something like this:<\/p>\n<div id=\"attachment_459\" style=\"width: 2056px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-459\" class=\"size-full wp-image-459\" src=\"https:\/\/gaconnector.com\/blog\/wp-content\/uploads\/2018\/10\/3e7ed8456c9c22708bb1805b446276db.png\" alt=\"Create GCLID field in Salesforce\" width=\"2046\" height=\"826\" srcset=\"https:\/\/gaconnector.com\/blog\/wp-content\/uploads\/2018\/10\/3e7ed8456c9c22708bb1805b446276db.png 2046w, https:\/\/gaconnector.com\/blog\/wp-content\/uploads\/2018\/10\/3e7ed8456c9c22708bb1805b446276db-300x121.png 300w, https:\/\/gaconnector.com\/blog\/wp-content\/uploads\/2018\/10\/3e7ed8456c9c22708bb1805b446276db-768x310.png 768w, https:\/\/gaconnector.com\/blog\/wp-content\/uploads\/2018\/10\/3e7ed8456c9c22708bb1805b446276db-1024x413.png 1024w, https:\/\/gaconnector.com\/blog\/wp-content\/uploads\/2018\/10\/3e7ed8456c9c22708bb1805b446276db-788x318.png 788w\" sizes=\"(max-width: 2046px) 100vw, 2046px\" \/><p id=\"caption-attachment-459\" class=\"wp-caption-text\">Create GCLID field in Salesforce<\/p><\/div>\n<h2>Step\u00a03 &#8211; Add GCLID hidden field to your forms<\/h2>\n<p>Add a hidden field to your forms that looks like this:<\/p>\n<blockquote><p>&lt;input type=&#8221;hidden&#8221; id=&#8221;gclid&#8221;&gt;<\/p><\/blockquote>\n<p>Make sure to connect this field with the Salesforce GCLID field you&#8217;ve just created.<\/p>\n<h2>Step 4 &#8211; Add\u00a0a script that will\u00a0populate the GCLID hidden field<\/h2>\n<p>This script will find a hidden field with id &#8220;gclid&#8221; and populate it with the actual value of gclid\u00a0parameter:<\/p>\n<pre class=\"lang:default decode:true \">&lt;script type=\"text\/javascript\"&gt;\r\n    function setCookie(name, value, days) {\r\n        var date = new Date();\r\n        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));\r\n        var expires = \"; expires=\" + date.toGMTString();\r\n        document.cookie = name + \"=\" + value + expires + \";path=\/\";\r\n    }\r\n\r\n    function getParam(p) {\r\n        var match = RegExp('[?&amp;]' + p + '=([^&amp;]*)').exec(window.location.search);\r\n        return match &amp;&amp; decodeURIComponent(match[1].replace(\/\\+\/g, ' '));\r\n    }\r\n    var gclid = getParam('gclid');\r\n    if (gclid) {\r\n        var gclsrc = getParam('gclsrc');\r\n        if (!gclsrc || gclsrc.indexOf('aw') !== -1) {\r\n            setCookie('gclid', gclid, 90);\r\n        }\r\n    }\r\n\r\n    function readCookie(name) {\r\n        var n = name + \"=\";\r\n        var cookie = document.cookie.split(';');\r\n        for (var i = 0; i &lt; cookie.length; i++) {\r\n            var c = cookie[i];\r\n            while (c.charAt(0) == ' ') {\r\n                c = c.substring(1, c.length);\r\n            }\r\n            if (c.indexOf(n) == 0) {\r\n                return c.substring(n.length, c.length);\r\n            }\r\n        }\r\n        return null;\r\n    }\r\n\r\n    window.onload = function() {\r\n        document.getElementById('gclid').value = readCookie('gclid');\r\n    }\r\n&lt;\/script&gt;<\/pre>\n<p>It&#8217;s best to put it before the closing &lt;\/body&gt; tag.<\/p>\n<h2>Want to learn more about Salesforce &amp; Adwords integration?<\/h2>\n<p>You can read our blog post to learn about our <a href=\"https:\/\/gaconnector.com\/blog\/salesforce-and-google-adwords-connector\/\">Salesforce &amp; Adwords integration<\/a>.<\/p>\n<p>Also, feel free to <a href=\"https:\/\/gaconnector.com\/contact-us\/\">contact us<\/a> if\u00a0you&#8217;d like us to help set up this integration for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Saving GCLID (Adwords click ID) to Salesforce is an essential part of Salesforce &amp; Adwords integration. In this article, we&#8217;ll show you step-by-step how you can do this. Step 1 &#8211; Make sure\u00a0that Adwords adds GCLID to ad URLs All you need to do is make sure that auto-tagging is enabled for your Adwords account&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"yst_prominent_words":[61,38,17,261,300,298,283,286,296,281,293,295,288,285,287,284,39,142,143,273],"_links":{"self":[{"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/posts\/455"}],"collection":[{"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/comments?post=455"}],"version-history":[{"count":8,"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":1182,"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/posts\/455\/revisions\/1182"}],"wp:attachment":[{"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/media?parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/categories?post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/tags?post=455"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/gaconnector.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}