Mautic Community Forums

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.

1 Like

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.