How To? Grabbing gclid and pushing into contact record

So I would like to take advantage of offline conversions with Google ADs but I need to provide the gclid querystring when visitors click my ADs.

How can I grab that querystring and save it to the anonymous visitor record?

Also, being that they will be an anonymous record. Would that record be converted into a known contact if the contact details were pushed in via a Zapier record push? I doubt it but…?

I use Square Appointments for my bookings. Square does not provide any method of tracking sales conversions. All sales happen in an iframe on a page in WP.

But if I can store the gclid to the contact I can then import them into Google Ads offline.

I’m thinking I would have to get them to provide an email address first before they create the booking. That way I can create the contact record in Mautic that the Zapier push from Square would then update.

2 Likes

In my previous life I have captured gclid in cookie and passed it to a Mautic hidden field with form submission. I am unfamiliar with your exact use cases to offer further suggestions.

2 Likes

This is exactly what I am looking to do. Do you recall how you went about doing this?

Alternatively, once a person hits the site, an anonymous record is created in Mautic. Once a form submit happens with an email address that anonymous record is converted into a contact. If there is a way to grab the gclid when the anonymous visitor is created that would make things a little more reliable as it would happen on the very first page load, whether that is the home page or a landing page.

Hello there. I had help from website developer who helped capture the gclid in a cookie using jquery.
There is also a Mautic cookie stored, I am sure it can be accessed as well. Not sure how to store additional values in it.

For Google adwords campaigns this use case is very useful and honestly not sure of the best way to do it with Mautic. But I would be curious to know! Looking forward to digging into this in the coming weeks. Hopefully this is helpful!

Do let me know how it goes!

First, create a custom field in mautic to hold the client id “ga client id”.

Then, you should be able to capture the ga client id from the ga cookie like so when the page loads:

ga(function(tracker) {
  var clientId = tracker.get('clientId');
});

Now that the ga client id is in a javascript variable, you need to push it into a hidden form field that is part of your mautic form. You will need the HTML ID of the field (I think you can set this in the mautic form).

Then do this:

<script>
document.getElementById('yourmauticfieldname').setAttribute('value', clientID);
</script>

When the user submits the form, the ga client id should now be associated with the contact.

I’ve done this before but not in a while, so you might have to fool with it, but these are the essential elements.

1 Like

Hey ericgr!

Thanks for jumping in!

I’ve managed to wrangle together a bunch of code that is ‘kinda’ doing the job. Reading your scripts I am wondering what the general consensus is regarding JScript errors on a page?

Using your code if the SQ was not present in the URL then it would throw an error.

In the jumble of code I wrote I tried to account for a couple of different scenarios.

  1. Is the QS present in the URL //if not an error pops
  2. If present, was it already set as a cookie //we don’t want to overwrite the existing value
  3. If present and set as a cookie, has it been sent to Mautic yet? //again, don’t want to overwrite
  4. If not sent to Mautic, send it. //see #3

My problem is it takes multiple page views before clients make a booking and JScipt vars are not session-based. So I have to set the value as a cookie and keep that for as long as they are on the site in the event they go to book.

1 Like

Hi @aglyons - I was just running into some trouble myself as I tried to get this working as a test on my site. Turns out that if you are running Google Tag Manager that there is a different set of code that you need. Still working on it, but if you want to google it its called ‘gtag’ instead of ‘ga’.

One thing I’m not clear of is why you are trying to get the CID from a query string? Unless I am misunderstanding.

The GA CID is set when someone visits a website for the first time and it stays the same for two years as long as you come back at least once every 90 days. So, I don’t think you need to get anything from the query string and you shouldn’t have to set it yourself for multiple sessions.

That’s a great question about capturing gclid for offline conversions with Mautic and Square Appointments.

The approach ledzee mentioned capturing the gclid in a cookie and passing it to a Mautic hidden form field is a common and effective method, especially for form submissions.

To address your goal of capturing the gclid right on the first page load and linking it to the Mautic anonymous visitor record, you’re on the right track with the anonymous record creation.

To grab the gclid reliably on the first page load, you can use a bit of JavaScript to read the URL parameter and then use the Mautic tracking script’s API or a custom pixel push to associate that value with the current anonymous profile.

This is more robust than relying on a cookie that might expire or be blocked.

For your anonymous record to become a known contact when an email is provided via a form, Mautic generally handles this by merging the anonymous tracking data (including the gclid you’ve pushed) with the new contact record created upon form submission, provided the form submit is tracked correctly.

The Zapier push from Square would ideally be updating an existing Mautic contact record, but if the email is a unique identifier, Mautic will match the incoming data to the previously anonymous contact.

While the cookie-and-form-field method works, for a truly robust and scalable setup that integrates Mautic, Square, and Google Ads for offline conversions, especially with an iframe involved, a server-side tracking approach using APIs and a dedicated tracking platform is often superior.

Instead of relying solely on client-side browser behavior (which can be blocked or lost), you would leverage the Mautic API, the Square API, and the Google Ads API, orchestrated by a system like Google Tag Manager (GTM) with a server-side component such as Stape or Google Cloud Platform.

Here is why this is a better solution:

When a visitor lands on your page, GTM captures the $gclid$ and immediately sends a Standard Event like page_view to your server-side tracking environment (Stape or GCP).

This environment then uses the Mautic API to update the anonymous contact’s record with the gclid.

When the booking happens in Square’s iframe, you may not have direct access to the form submission, but after the booking, Square’s API can send a webhook or Zapier can push the booking confirmation data (including the email and a unique ID) to your server.

This unique ID and email are then used to query the Mautic API to retrieve the associated gclid and other necessary data.

Once you have the gclid and the conversion value, your server-side system can then use the Google Ads API to send the offline conversion, which is far more reliable and secure than client-side methods.

This structure provides more resilience against browser privacy restrictions, maintains a single source of truth for your data on the server, and gives you complete control over when and how the conversion is sent to Google Ads, allowing you to bypass the limitations of the iframe and Square’s lack of direct conversion tracking.