How to add Google Ads Conversion Tracking GCLID to Contact Form 7

Latitude Innovation Sdn Bhd
4 min readNov 29, 2021

What is GCLID?

GCLID (Google Click Identifier) is the parameter added to the end of the URL path. It helps to identify the Google Ads that result in conversion.

What is Contact Form 7?

Contact Form 7 is a plugin that helps to create contact form(s) that can be reused on your website. It provides flexibility to embed in the website using shortcode. You can also use simple markup to customize the mail content.

What is offline conversion?

It’s the ad results which cause sales though offline paths such as a call to the company. You need to enable auto tagging to track offline conversion.

Steps Overview

  1. Enable Auto-tagging
  2. Create conversion action
  3. Add hidden field in Contact Form 7
  4. Store GCLID using Google Tag Manager

How to enable Auto-tagging?

  1. Sign into your Google Ads
  2. Click Settings > Account Settings

3. Search for Auto-tagging and check the box of “Tag the URL that people click through from my ad” and click Save

The Auto-tagging should become Yes now

Create one or more conversion actions

Refer Google docs Part 1 for details: https://support.google.com/google-ads/answer/7012522?hl=en

How to add hidden field in Contact Form 7?

  1. Install and activate Contact Form 7 plugin if not yet
  2. Create a new contact form
  3. Go to Form tab and add hidden field as below:
[hidden textarea-gclid id:gclid_field]

4. Next, go to Mail tab, add mail tags of [textarea-gclid] in Message body to capture GCLID value

How to use Google Tag Manager to capture and store GCLID?

  1. Open your Google Tag Manager account
  2. Click the name of the container

3. Go to “Tags” from left sidebar

4. Click “New” button at top right

5. Give your Tag a name

6. Click the pencil icon to choose a tag type

7. Select “Custom HTML” for tag type

8. Copy the javascript below into the HTML field

<script>
function getParam(p) {
var match = RegExp('[?&]' + p + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
function getExpiryRecord(value) {
var expiryPeriod = 90 * 24 * 60 * 60 * 1000; // 90 day expiry in milliseconds
var expiryDate = new Date().getTime() + expiryPeriod;
return {
value: value,
expiryDate: expiryDate
};
}
function addGclid() {
var gclidParam = getParam('gclid');
var gclidFormFields = ['gclid_field', 'foobar']; // all possible gclid form field ids here
var gclidRecord = null;
var currGclidFormField;
var gclsrcParam = getParam('gclsrc');
var isGclsrcValid = !gclsrcParam || gclsrcParam.indexOf('aw') !== -1;
gclidFormFields.forEach(function (field) {
if (document.getElementById(field)) {
currGclidFormField = document.getElementById(field);
}
});
if (gclidParam && isGclsrcValid) {
gclidRecord = getExpiryRecord(gclidParam);
localStorage.setItem('gclid', JSON.stringify(gclidRecord));
}
var gclid = gclidRecord || JSON.parse(localStorage.getItem('gclid'));
var isGclidValid = gclid && new Date().getTime() < gclid.expiryDate;
if (currGclidFormField && isGclidValid) {
currGclidFormField.value = gclid.value;
}
}
window.addEventListener('load', addGclid);
</script>

9. Edit line 18 above (gclidFormFields)and add form field id if any

10. Click pencil icon to choose a trigger

11. Select “All Pages”

12. Click “Save” button on top right to save changes

13. Last, you can test by clicking the ads with conversion and submit the Contact Form 7 in website.

You should get an email with GCLID.

If you are still facing difficulties in enabling Auto tagging for Google Ads or store GCLID in Contact Form 7, kindly contact us at inquiry@latitudeinnovation.com.my or +6010–434 8799.

--

--