Manually import Google Ads conversions from Salesforce

Google Ads offers a way to automatically import conversions from Salesforce. But if you don’t think that solution is right for your business, you can manually import conversions from Salesforce.

This article explains how to set up your Salesforce account and manually import conversions into Google Ads. 

Before you begin

To use this feature, you’ll need to meet the following requirements:

  • Be able to sign in to a Salesforce Sales Cloud® account.
  • Have auto-tagging enabled in your Google Ads account(s).
  • Be able to edit your website code. You or your web developer will have to edit your code to capture the Google click ID (GCLID).
  • Be able to make changes in your Salesforce® account, including creating custom fields and enabling field history tracking.
  • Have a click-to-conversion cycle that's less than 90 days. Any conversion uploaded more than 90 days after the last click associated with it occurred will not be imported by Google Ads, and will therefore not show up in your conversion statistics.
  • Use Salesforce’s Web-to-Lead feature, or another solution to send leads to Salesforce.

How it works

No two businesses are alike, and there are endless ways that you can define your lead and opportunity stages. But you'll only want to import some of those as Google Ads conversions.

We'll use one sample scenario below to show you how the integration works, and then give you some ways to customise that to your situation later in this article.

Here's the sample sales process:

  1. A prospective customer clicks on your ad, which leads to your website.
  2. The prospective customer explores your web pages – they read descriptions, watch videos and download whitepapers. During that session, or a later one, they enter their information into your lead submission form that uses Salesforce's Web-to-Lead solution.
  3. A lead is created in Salesforce.
  4. When the lead becomes "qualified", it's converted to an opportunity. Then an opportunity record is created, with the initial stage 'prospecting'.
  5. When the opportunity is won and closed, the opportunity stage is set to 'Closed Won'.
  6. Finally, you want to measure when a click leads to both a qualified lead and a final sale.
 

See the technical details for this process
Channel Key event Technical details
Online A prospective customer clicks on your ad, which leads to your website. Google passes the GCLID to the website.
Online The prospective customer explores your web pages – they read descriptions, watch videos and download whitepapers. During that session, or a later one, they enter their information into your lead submission form that uses Salesforce's Web-to-Lead solution. Using the JavaScript code samples below, the website stores the GCLID in a cookie and then passes the GCLID value (along with the lead information entered on the form) to Salesforce.com. Note: If you'd like to track this lead submission as a conversion, you could use Google Ads conversion tracking to track conversions on a website.
Offline A lead is created in Salesforce. Salesforce.com creates a new lead that stores the lead's information + GCLID
Offline When the lead becomes "qualified", it's converted to an opportunity. Then an opportunity record is created, with the initial stage 'prospecting'. Salesforce stores this conversion event in the opportunity history so that Google Ads can later retrieve exactly when the click resulted in a new opportunity (aka qualified lead)
Offline When the opportunity is won and closed, the opportunity stage is set to 'Closed Won'. Salesforce stores this conversion event in the opportunity history so that Google Ads can later retrieve exactly when the click resulted in a final sale, or "win".

Set up

Below, we'll show you how a Sales Cloud administrator can do the following:

  • Set up custom fields in which to store the GCLID and related information.
  • Capture the Google Ads click ID ("GCLID").
  • Modify your Web-to-Lead HTML form in order to pass the GCLID to each new lead record.
  • Download the relevant data so that you can upload your conversions into Google Ads.
Step 1: Configure your Salesforce account
  1. Create a custom field called 'GCLID' (API name is GCLID__c) on the lead object as well as on the opportunity object. The field length is 255 characters. Make this field read-only, as this will be automatically populated.
  2. Create a custom text formula field called 'Google Ads Action' on both the lead and opportunity object (the API name is Google Ads_Action__c). Enter the simple formula 'add'. This field will always contain the static value 'add', and is used later to simplify the creation of the data file that the admin feeds back into Google Ads.
  3. In the Lead Custom Field Mapping screen, map the lead field GCLID to the opportunity field GCLID. That way, the GCLID is transferred from the lead to the opportunity automatically when a lead is converted into an opportunity.
Step 2: Edit your website to save the click ID in a cookie

If a visitor clicks on your ad, Google Ads will append the URL parameter 'gclid' to the URL that leads to your landing page.

You'll need to store this parameter's value in a cookie to retrieve it later when a prospective customer enters their data into the Web-to-Lead form.

If you embed the following JavaScript code immediately before the closing </body> tag of your landing page(s), the GCLID value will be saved in a cookie.
<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;
}
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>

 

We strongly recommend that you insert this code on every web page on your site. This way, you won't need to add it every time you create new ads with new landing pages. You also won't have to worry about losing GCLIDs if you start driving ads traffic to different landing pages. Consider adding this code to your web page template (or a shared page element, such as the footer), so that all of your new pages will automatically include the code.

Step 3: Adjust your Salesforce Web-to-Lead form

To associate and store the GCLID with the lead information, you'll need to modify your Web-to-Lead submission forms so all new leads will include the GCLID value.

This means that after the GCLID has been saved in a cookie, you'll add a hidden field to your lead forms, and write the value of the cookie into that field so it can be transmitted to Salesforce.

Bear in mind: Your Web-to-Lead form needs to be located in the same domain as the rest of your web pages in order to make the cookie available.

  1. Generate a standard Web-to-Lead form, and include all the fields that you want your prospects to submit. Also include the lead field "GCLID". The HTML generated by Salesforce will include this code (where xxxx stands for the ID of the field GCLID that you've created):

    GCLID:<input id="xxxx" maxlength="255" name="xxxx" size="20" type="text" />

  2. Change this code to: <input id="xxxx" name="xxxx" type="hidden" />

    These changes mean that you're removing the attributes 'maxlength' and 'size', and changing the value of the type attribute to 'hidden'. Leave the attributes "id" and "name" as is (they'll be different for every Salesforce organisation).

  3. Once you have created this new hidden input field, add it to your HTML form in between the <form> tags. On the same HTML lead submission page, add the following code between the head tags:
            <script> 
            window.onload = function getGclid() {        
                 document.getElementById("xxxx").value = (name = new    
            RegExp('(?:^|;\\s*)gclid=([^;]*)').exec(document.cookie)) ? 
            name.split(",")[1] : ""; }
            // window.onload() may not be supported by all browsers.  
            // If you experience problems submitting the GCLID as a
            // hidden field, consider using an alternative method to
            // call this function on page load.
            </script>
         

    In this code replace 'xxxx' with the ID of your new field.

Salesforce and your web pages are ready to gather all the data. This script will populate the hidden field with the GCLID value, and populate the field Lead.GCLID__c when the web-to-lead form is submitted. Again, bear in mind that the fields 'ID' and 'name' will be different in your organisation.

Step 4: Export the key event data

This next step assumes that you're exporting and uploading your key event data every three days.

  1. Use Apex Data Loader or Lexi Loader to export OpportunityHistory records using this query:
            SELECT Opportunity.Google Ads_Action__c, Opportunity.GCLID__c, 
            StageName, ExpectedRevenue, CreatedDate FROM OpportunityHistory 
            WHERE Opportunity.GCLID__c != null AND (StageName = 
            'Prospecting' OR StageName = 'Closed Won') AND CreatedDate = 
            LAST_N_DAYS:3
         

    This will output a row for every GCLID associated with an opportunity that has been set to the 'Prospecting' or 'Closed Won' stages. And it will contain all the fields necessary (and in the right order) to quickly create a Google Ads conversion import CSV. Alternatively, if you wish to automate the conversion import process by using the Google Ads API (AdWords API), then you can skip the next two steps and instead refer to our conversion import API guide.

  2. Once you have the export file, replace the first row of the file with these two rows:
           Parameters:EntityType=OFFLINECONVERSION;TimeZone=HHMM; 
           Action,Google Click Id,Conversion Name,Conversion 
           Value,Conversion Time
         
  3. Finally, update the 'TimeZone' value so that it reflects your Google Ads account's time zone (e.g. +0100 for BST). You can see what time zone your account is set to by signing into your Google Ads account and checking the footer.

This file is now ready to be uploaded into Google Ads. If you need guidance on uploading your files, read our article about tracking offline conversions.

Tip

Because the conversion names that we export are opportunity stage values, you might want to set up your Google Ads conversion actions to have the same name. For example, if 'IS Lead Qualified' is used in Salesforce to show that the lead has become qualified, then you'd want to create a conversion type in Google Ads with the name 'IS Lead Qualified'.

If you don't do this, you'll need to open your Salesforce CSV export file and change all the Conversion Name Values to whatever conversion action name you defined in Google Ads.

Customise to your business

Your business model and sales process might differ from the example that we've outlined here. If that's the case, consider these modifications:

  • If you want to consider only a subset of you opportunities (e.g. just a specific record type), add additional clauses to the WHERE part of the SOQL query (e.g. ...AND RecordType.Name = 'Electronics' )
  • If you want to update the conversion tracking data more or less frequently than every three days, modify the SOQL query respectively (e.g. CreatedDate = LAST_N_DAYS:7) and generate and upload the CSV file within your preferred time interval.
  • If you find other events in your sales process (e.g. opportunity stages) useful for optimising your campaigns (e.g. 'Paperwork Out'), you'd want to modify these points:
    • Add conversion actions in Google Ads that have exactly the same name as the additional opportunity stages that you find relevant.
    • Modify the SOQL query and add additional clauses within the parenthesis (e.g. …OR StageName = 'Paperwork Out')
  • If the relevant events are not only on the opportunity but also on the lead object, you'll want to modify these points:
    • Add conversion actions in Google Ads that have the same name as the lead statuses that you find relevant.
    • Query the LeadHistory object to get the names and time stamps (CreatedDate) of when the field 'Status' changed its value to the value that you find relevant. You'll want to join the results set of both queries into one CSV file. Make sure that the columns match the specified format.

Was this helpful?

How can we improve it?
Search
Clear search
Close search
Main menu
14222030747576642760
true
Search Help Centre
true
true
true
true
true
73067
false
false
false