Overview
This article documents how to capture the Google Click ID (GCLID) from a Google Ads URL and pass it through a Gravity Forms submission into Zoho CRM as the native $gclid system field.
The GCLID is appended to your landing page URL by Google Ads when a user clicks your ad (e.g. yoursite.com/contact/?gclid=ABC123). Capturing and storing this value in Zoho CRM enables accurate attribution of leads back to specific Google Ads clicks.
Why the Built-In Feed Mapping Does Not Work
The Gravity Forms Zoho CRM add-on includes a field mapping UI where you can map form fields to Zoho CRM fields. However, $gclid is a Zoho system field, not a regular custom field. When you map to it through the UI, Zoho receives it as a custom field named GCLID rather than the system parameter $gclid, so it does not get stored against the correct attribute.
The solution requires two components:
• A JavaScript snippet that captures the GCLID from the URL (or a cookie) and populates a hidden field in the form.
• A PHP snippet that intercepts the lead data before it is sent to Zoho and injects $gclid as a proper system parameter.
• Gravity Forms with the Zoho CRM add-on installed and a feed configured
• Code Snippets plugin installed (wordpress.org/plugins/code-snippets)
• A Hidden field in your Gravity Forms form with Field ID 13 (adjust if different)
• The Zoho CRM feed mapping for GCLID removed from the feed UI
Part 1: JavaScript — Capture and Populate GCLID
What It Does
This script runs on every page of your site and does the following:
• Reads the gclid URL parameter if present on the current page.
• Stores it in a browser cookie named zc_gclid for 90 days so it persists across page visits.
• When a Gravity Form loads (including forms loaded via AJAX), it populates the hidden GCLID field (field ID 13) with the stored value.
Where to Add It
In the Code Snippets plugin, create a new snippet, set the type to JavaScript and the run location to Site Wide Footer, then paste the code below.
The Code
function getParam(p) {
var match = RegExp('[?&]' + p + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
function getCookie(name) {
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match ? match[2] : null;
}
function setCookie(name, value, days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = name + '=' + value + '; expires=' + date.toUTCString() + '; path=/';
}
var gclid = getParam('gclid');
if (gclid) {
setCookie('zc_gclid', gclid, 90);
}
function populateGclid() {
var storedGclid = getParam('gclid') || getCookie('zc_gclid');
if (storedGclid) {
jQuery('#input_1_13').val(storedGclid);
} else {
console.log('No GCLID found in URL or cookie');
}
}
jQuery(document).ready(function() {
populateGclid();
});
jQuery(document).on('gform_post_render', function() {
populateGclid();
});
📌 Replace #input_1_13 if your form ID or field ID is different. The format is #input_{FORM_ID}_{FIELD_ID}.
How the Cookie Works
A user may land on your site via a Google Ad click on one page, then navigate to a different page before submitting the form. The GCLID is only present in the URL on the initial landing page. The 90-day cookie ensures the GCLID is still available when the form is submitted on a different page or in a later session.
Part 2: PHP — Pass GCLID to Zoho CRM
What It Does
This filter hooks into the Gravity Forms Zoho CRM add-on just before the lead data is sent to the API. It reads the value from field 13 in the form entry and injects it into the lead array using the key $gclid, which Zoho CRM recognises as its native system field for Google Click IDs.
Where to Add It
In the Code Snippets plugin, create a new snippet, set the type to PHP and the run location to everywhere, then paste the code below.
The Code
add_filter( 'gform_zohocrm_lead', function( $lead, $feed, $entry, $form ) {
$lead['$gclid'] = rgar( $entry, '13' );
return $lead;
}, 10, 4 );
📌 Replace '13' with your actual hidden field ID if it differs.
Why This Works When the Feed Mapping Does Not
The gform_zohocrm_lead filter gives direct access to the raw data array sent to the Zoho API. Setting the key as $gclid (with the dollar sign) tells the Zoho API to write the value to its internal GCLID system field, not a custom field. The feed mapping UI cannot produce this key correctly because it treats the dollar sign as a literal character rather than a system field prefix.
1. Add a Hidden field to your Gravity Form. Note the Field ID from the right sidebar.
2. In your Zoho CRM feed, remove any existing mapping for the GCLID field.
3. Add the JavaScript snippet in Code Snippets as a Site Wide Footer script.
4. Add the PHP snippet in Code Snippets set to run everywhere.
5. Test by visiting your form page with ?gclid=TEST123 appended to the URL, submitting the form, and confirming the $gclid field in Zoho CRM shows TEST123.
GCLID not populating in the hidden field
• Open browser DevTools and check the Console for 'No GCLID found in URL or cookie'.
• Confirm the URL contains ?gclid= when you load the page.
• Check that the jQuery selector #input_1_13 matches your form and field IDs.
GCLID appears in a custom field in Zoho instead of $gclid
• Confirm the PHP snippet is active in Code Snippets.
• Check that the old GCLID mapping has been removed from the Zoho feed settings.
• Verify the field ID in the PHP snippet matches your actual hidden field ID.
GCLID is empty in the Gravity Forms entry
• The JavaScript may not be running before the form renders. Confirm the snippet is set to Site Wide Footer.
• If the form loads via AJAX, confirm the gform_post_render handler is present in the JS snippet.
This solution uses the Code Snippets plugin so it will not be affected by theme updates.