If you're reading this, it means you're probably trying to set up offline conversion tracking for your Google Ads campaign. It allows you to track offline sales conversions in your Google Ad campaign.
This makes it easier of course to optimize your ad campaign to increase your return on ad spend by giving you cost per offline sale data instead of just cost per call/form submission data.
Visitors who come to your website by clicking on your Google Ad are tagged (I'm assuming you already have enabled Google Ads auto-tagging) with a unique ID called the GCLID, which I believe stands for 'Google Click ID'. The GCLID string of random letters and numbers that makes a unique ID for that visitor. It's found in the URL when they click over to your landing page and looks something like this:
Now the goal here is to get that GCLID into a hidden form field in the form and so if the Google Ad visitor fills out the form, their unique GCLID will be passed along with their info into your sales CRM.
The trick then is how to grab this unique GCLID data found in the URL (i.e. query string parameter data) automatically when the page loads and put it into the hidden form field.
Here's the code that I use for this:
var urlParams = new URLSearchParams(window.location.search);
const gclid = urlParams.get('gclid');
document.getElementById("gclidInput").value = gclid;
This code assumes the ID on the hidden form field element is 'gclidInput'.
Note: Keep in mind that the GCLID query string data disappears if they visit another page of your website, so this will only work if the landing page also has the form they'll be submitting.
Are you tired of reading tutorials and ready to learn how to set up and optimize your Google Ad Campaign with a professional?