Integrate Google AdWords with Your Salesforce Org Through Pardot

If you use Pardot to handle your marketing campaigns and have tried to integrate your Google AdWords to your Salesforce org, you have probably noticed that Google does not provide any step-by-step solutions on how to integrate all three of them together to track your clickable ads. It took some time, but after some coding changes and a rather long phone call with Google, there is a solution that can now be followed to solve this.

If you are using a native Salesforce web-to-lead form, then you can find standard support here from Google. If you use Pardot for your landing pages, continue reading below to get some help integrating Google AdWords and Salesforce through Pardot.

Setting Up Your Files

Create new GCLID Fields

To start off, let’s create new GCLID fields on both the opportunity and lead objects. See Figures 1 and 2 below.
[su_row]

Add the GCID field to the Oportunity
Figure 1. Add the GCID field to the Opportunity
Add tje GCID field to the Lead
Figure 2. Add the GCID field to the Lead

After the two fields have been created on the opportunity and lead objects, we must map the fields, as shown in Figures 3 and 4.

Figure 3 for the "Integrate Google AdWords with Your Salesforce Org Through Pardot
Figure 3. Begin to map the lead fields.
Figure 4. Mapping the Lead and GCID fields
Figure 4. Mapping the Lead and GCID fields

Add the script to your landing pages

Now that the configurations have been completed, it’s time to touch some code on your website. If you don’t have access to this, contact your webmaster to help with this step. A cookie value needs to be stored on your website to save the GCLID based on the ad that is clicked on. The following script should be added before your tags on all of your landing pages on the website.

<script type="text/javascript">
    function setCookie(name, value, days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
        document.cookie = name + "=" + value + expires + ";domain=" + location.hostname.replace("www.", '');
    }
    function getParam(p) {
        var match = RegExp('[?&]' + p + '=([^&]*)').exec(window.location.search);
        return match && decodeURIComponent(match[1].replace(/+/g, ' '));
    }
    var gclid = getParam('gclid');
    if (gclid) {
        var gclsrc = getParam('gclsrc');
        if (!gclsrc || gclsrc.indexOf('aw') !== -1) {
            setCookie('gclid', gclid, 90);
        }
    }
</script>

Create a hidden field

Once this step is completed, we will now focus on the Pardot portion of the integration. To start off, on your landing pages, create a hidden field labeled GCLID.

Figure 5. Create a hidden GCID field
Figure 5

Add code snippet to your form

Next, on the same form, click on “Look and Feel” on the menu bar towards the top of the page. You will see a “Below Form” tab which should be clicked on. When clicked, all the way to the right you will see an html button (next to the omega symbol) click that.

Figure 6. Add code snippet to your form.
Figure 6
<script>
  window.onload = function getGclid() {
    document.getElementById("xxxx").value = (name = new RegExp('(?:^|;\s*)gclid=([^;]*)').exec(document.cookie)) ? name.split(",")[1] : ""; }   
</script>
<script>
  var putGCLID = function() {
    document.getElementById("xxxx").value = (name = new RegExp('(?:^|;\s*)gclid=([^;]*)').exec(document.cookie)) ? name.split(",")[1] : "";
  };
  document.getElementById('pardot-form').addEventListener("submit", putGCLID, true);
</script>

The “xxxx” in the document.getElementById is the id of the GCLID field on your form and the “pardot-form” is the id of the entire form.” Can view the id by right-clicking on the form area, clicking “Inspect” and finding the code for the GCLID field and copying it’s id. Repeat for the form area also.

After this piece of code is inserted into the Pardot form, you are now ready to test the integration between Salesforce and Google AdWords through Pardot. In the URL of your contact us page, add “?gclid=blogTest” (or any testing word) at the end as shown below.

www.soliantconsulting.com/contact?gclid=blogTest

Find the information submitted

Once you submit the lead information, in Salesforce, go to Leads and find the information that you submitted (see Figure 7).

Figure 7. Find the information you submitted
Figure 7

Keyword added to the GCLID field

In the GCLID field, you should see the keyword that you entered at the end of the URL in the step above, in my case being “blogTest” as shown in Figure 8.

Figure 8. Keyword added to the GCLID field
Figure 8

When the link is successful — meaning you see the keyword “blogTest” that you entered into the URL in your lead in Salesforce — then you have now integrated Google AdWords with Salesforce through Pardot! The final step, is to link your Salesforce account to your Google AdWords account.

Link Your Salesforce and Google AdWords Accounts

Sign in to your Google AdWords account and on the right hand side next to your customer id, you will see a cog. When you click on the cog, there should be a link called “Linked accounts.”

Figure 9. Click on the cog to access "Linked accounts"
Figure 9

Choose accounts to link to Google AdWords

After you have clicked the Linked accounts link, you should be on the following page. Here you can choose which accounts to link to your Google AdWords account. In our case, click on “View details” under Salesforce.com.

Figure 10. Choose an account to link to Google AdWords
Figure 10

Log into your Salesforce organization

Finally, click on the “+ Account” button on the page and you will be redirected to the Salesforce authentication page to login to your Salesforce organization.

Figure 11. Use the add account button.
Figure 11

Once your Salesforce organization is linked, you will be prompted to set up conversions that are relevant to your Google ads. After you set up these conversions, you are now ready to completely track your clickable ads with AdWords and Salesforce through Pardot.

16 thoughts on “Integrate Google AdWords with Your Salesforce Org Through Pardot”

  1. Hi Uriel,

    I really appreciate this article. It was very informative and is giving me the exact information I am looking for. I’m having trouble though. I have added the script to my landing page, a hidden GCLID field on my Pardot form and the HTML code in the “below form” section; but when I go to test the passing of the GLCID data by adding ?gclid=trackingtest, this information is not pulling into the prospect record in Pardot or lead record in Salesforce. Any insight? Was there a certain edit I was to make to the “below form” code or anything of the sort?

    1. Uriel Gutierrez

      Hi Sean,

      Thanks for reaching out to us! It looks like there was a snippet of code missing in the post. I updated the post to include the missing snippet along with some info on what the values are.

      Uriel

  2. This post help us a lot, but there is an small typo on the second script, in line 3 you have “document.getElementByID” when it should be “document.getElementById” (the uppercase D at the end), and a ΓÇ£ instead of ” in line 7. Thanks

  3. Hi Uriel,

    Firstly thanks for this beautiful article. I have a doubt here.
    The pardot account which i am using is having 100 of campaigns and is connected to various connectors. how do i identify which are the google Ads present in my pardot.
    after that i need to setup GLID for each.

    1. Uriel Gutierrez

      Hi Ashish,

      I’m not sure I’m understanding your question correctly. Once you setup Google Adwords to start tracking your conversions that’s where you should be able to see which pages are being tracked. Let me know if that helps clear things up. If not, I’m happy to discuss further.

  4. I cannot get the GCLID to pass through to pardot/salesforce. Please help!

    I added this before all the tags in the header.php file…..

    function setCookie(name, value, days){
    var date = new Date();
    date.setTime(date.getTime() + (days*24*60*60*1000));
    var expires = “; expires=” + date.toGMTString();
    document.cookie = name + “=” + value + expires;
    }
    function getParam(p){
    var match = RegExp(‘[?&]’ + p + ‘=([^&]*)’).exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ‘ ‘));
    }
    var gclid = getParam(‘gclid’);
    if(gclid){
    var gclsrc = getParam(‘gclsrc’);
    if(!gclsrc || gclsrc.indexOf(‘aw’) !== -1){
    setCookie(‘gclid’, gclid, 90);
    }
    }

    and this below the pardot form…. (the 680763 number was pulled from “inspect” of the url form”

    window.onload = function getGclid() {
    document.getElementById(“680763_35783pi_680763_35783”).value = (name = new RegExp(‘(?:^|;\s*)gclid=([^;]*)’).exec(document.cookie)) ? name.split(“,”)[1] : “&”; }

    var putGCLID = function() {
    document.getElementById(“680763_35783pi_680763_35783”).value = (name = new RegExp(‘(?:^|;\s*)gclid=([^;]*)’).exec(document.cookie)) ? name.split(“,&”)[1] : “&”;
    };
    document.getElementById(‘pardot-form’).addEventListener(“submit”, putGCLID, true);

    The code that you provided above was visible on the frontend of the website and on the form so I had to swap the characters out (<, >, &, " etc.) will this effect the outcome?
    Also, I found the id for the GCLID but couldn’t find the id for the form. The id for the form was showing “pardot-form”, am I supposed to leave it as “pardot-form” or replace it with a number of some sort? Thank you in advance!

    1. Hi Nik,

      From what I’ve read, your code seems to be missing the domain part of setting the cookie in the setCookie method.


      document.cookie = name + "=" + value + expires + ";domain=" + location.hostname.replace("www.", '');

      Aside from that it looks to be right. I would contact Pardot and/or Google support if adding the above doesn’t work.

      The id of the form will be “pardot-form.” You can leave this as-is.

      Uriel

  5. Hey Uriel pls help me in setting GCLID and GA visitor Id..as I have implemented script and all but..in a published form the GCLID fields is getting blank,.what;s the reason behind,..Am I missing something..I am attaching code snippet..Pls have a look..my email id is aashi.vashisth@gmail.com

    (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,’script’,’https://www.google-analytics.com/analytics.js’,’ga’);
    ga(‘create’, ‘UA-xxxxx-1’, ‘auto’);
    ga(function(tracker) {
    var clientId = tracker.get(‘clientId’);
    tracker.set(‘dimension1’,clientId);
    });
    ga(‘send’, ‘pageview’);

    window.onload = function getGclid() {
    document.getElementById(” “).value = (name = new
    RegExp(‘(?:^|;\\s*)gclid=([^;]*)’).exec(document.cookie)) ?
    name.split(“,”)[1] : “”;
    document.getElementById(“xx “).value = (name = new
    RegExp(‘(?:^|;\\s*)_ga=([^;]*)’).exec(document.cookie)) ?
    name.split(“,”)[1].split(“.”).slice(2).join(“.”) : “”;
    }

    function setCookie(name, value, days){
    var date = new Date();
    date.setTime(date.getTime() + (days*24*60*60*1000));
    var expires = “; expires=” + date.toGMTString();
    document.cookie = name + “=” + value + expires;
    }
    function getParam(p){
    var match = RegExp(‘[?&]’ + p + ‘=([^&]*)’).exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ‘ ‘));
    }
    var gclid = getParam(‘gclid’);
    if(gclid){
    var gclsrc = getParam(‘gclsrc’);
    if(!gclsrc || gclsrc.indexOf(‘aw’) !== -1){
    setCookie(‘gclid’, gclid, 90);
    }
    }

    1. Hi Ankita,

      Based on a quick glance at the JavaScript you provided, it looks like you are missing the id of the elements. Please refer to the JavaScript code snippet in the “Add code snippet to your form” section of the blog. The document.getElementById(‘element-id’) value must be filled in for both the field that contains the GCLID, and the form itself. Otherwise, you are not grabbing any of the values to pass.

      Uriel

  6. Hey Uriel –
    I’m trying to set this up in my org and I’m reading a lot of articles about it. One article mentioned that the gclid will not be available if you have auto-tagging turned on in google ads… Do you know anything about that? Does the account you work in, have the auto-tagging feature turned on or off?

    Thanks,
    Jen

    1. Uriel Gutierrez

      Hi Jen,

      Auto-tagging appends the gclid to the end of the URL for you. If your website isn’t showing the gclid, it could be that it’s not configured properly to handle the parameters being passed into the URL. Otherwise, I don’t see any indication that if you have auto-tagging turned on in google ads that the gclid won’t be available. I would check with your site administrator and see if there’s anything that would cause the gclid to not be present on the URL. The account we work in is managed by our marketing team, but I would be surprised if it’s not enabled as that feature is used in other parts of ads.

      Thanks,
      Uriel

  7. I’ve implemented this via our Org/Website and it works perfectly. We weren’t quite using web-to-lead Salesforce forms, but instead our forms are used by Gravity Forms and Pardot. Gravity Forms has an option to allow redirect and the web form info can be passed via a web form handler.

    This solution only caters for a web form lead, I’m also looking to implement GCLID if a phone call event occurs, any ideas?

    1. Hi Rushax, I’ve taken some time to research this but haven’t come up with a good solution. My team and I would be happy to dig into this further if you’d like to kick off a small consulting engagement. Just email us at info@soliantconsulting.com to get that process started.

      1. A late reply apologies. After also doing some research, I’ve found some solutions that may be of use to yourselves or anyone else that comes here. Any tracking of GCLIDs from a direct PPC Call Extension need to have a Google Forwarding numbers attached in order to extract the GCLID from Google Ads. If a user was to visit the website, a cookie would need to be stored upon the users initial landing and the call tracking software can push the call information into Salesforce details alongside the GCLID.

  8. Hey Uriel, this has been extremely helpful thank you! I got a couple of errors, not sure what we did wrong. I have listed the problem spots first and then the full code snippet below.
    1) return match && decodeURIComponent(match[1].replace(/+/g, ‘ ‘)); Error: Uncaught Syntax: Invalid regular expression: /+/g nothing to repeat
    2) addEventListener(“submit”, putGCLID, true); Error: Uncaught Type Error: Cannot read property of null
    3) (name = new RegExp(‘(?:^|;\s*)gclid=([^;]*)’).exec(document.cookie)) ? name.split(“,”)[1] : “&”; } Error: Uncaught TypeError: Cannot set property ‘value’ of null

    window.onload = function getGclid() {
    document.getElementById(“813433_34207pi_813433_34207”).value = (name = new RegExp(‘(?:^|;\s*)gclid=([^;]*)’).exec(document.cookie)) ? name.split(“,”)[1] : “&”; }

    var putGCLID = function() {
    document.getElementById(“813433_34207pi_813433_34207”).value = (name = new RegExp(‘(?:^|;\s*)gclid=([^;]*)’).exec(document.cookie)) ? name.split(“,”)[1] : “;”;
    };
    document.getElementById(“Contact Flyer”).addEventListener(“submit”, putGCLID, true);

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top