Storing Google Ads GCLID in Google Analytics

How and why to store the Google Ad’s “Google Click Identifier” in Google Analytics.

Google tracks every single click of your Google Ads with a unique identifier called, straightforwardly enough, the “Google Click Identifier” or GCLID.

The GCLID serves two purposes. First, it auto-tags traffic in Google Analytics, which is how Google Analytics knows that a user came from Google Paid Search and what keyword they searched for to find your ad and end up on your site.

Second, Google Ads stores the GCLID forever so you can later associate offline sales information with an actual ad click, which helps improves your campaign’s performance.

Since the GCLID is so powerful and important, you’d think it would be available for you to download by default GA. But, alas, the Google Gods have not deemed us worthy of this powerful tool.

However, with Google Tag Manager and a little ingenuity, we can steal the GCLID fire from the Gods and stash it as a GA custom dimension or use wherever we like.

Here’s how.

Download the recipe here.

Create a session-level custom dimension

First, we’ll create a session-level custom dimension in Google Analytics where we’ll stash the GCLID.

Go to the GA admin panel for your property and select Custom Definitions -> Custom Dimensions -> New Custom Dimension.

Then enter GCLID for the name and select Session as the scope and hit Create.

alt_text

We select a session-level scope and not a user-level because a single ad click results in one session.

For example, the same user could click on one ad on Monday and a second ad on Thursday. If they convert on the Monday ad, we want to associate the conversion with the Monday click (and hence its GCLID) not the Thursday click.

Note the index of the GCLID custom dimension because we’ll need it later.

Install the capture script

Now we need to capture the GCLID in GTM. You’ll notice that when you click on a Google Ad that the GCLID is passed to Analytics (and everything else) as a URL parameter like so.

https://slideruletech.com?**gclid=CjwKCAjw2Jb7BRBHEiwAXTR4jXtJNL9hLcm_8r-QU4I8yX9x_rlAwR1ashiV-YGJxn3AaDewAbmmFhoCTscQAvD_Bwf**

You might think we could just grab the GCLID as a URL parameter variable in GTM. However, if the user navigates to a second page, the GCLID parameter will disappear.

Therefore, we need a more sophisticated method to capture the GCLID and store it.

To do so, we’ll use this recipe (an updated version of this Bounteous container) that imitates how Google Analytics (used to) stores the GCLID (and a host of other useful variables) in a cookie.

Download the utmz-cookie-replicator.json file and import it into your Tag Manager container.

After doing so, put the container in preview mode, and go to your website, manually adding a ?gclid=test to the end of your URL. For example:

https://slideruletech.com?gclid=test

Click Container Loaded -> Variables and you should see a variable named JS - GA GCLID with the value test like so.

alt_text

You’ll also notice that you now have Source, Medium, Campaign, and a host of other goodies available in GTM that you can use (for example, you could submit them with hidden form fields).

Adding the GCLID to the custom dimension

Now that we have the GCLID available as a variable in GTM, it’s a simple matter of adding it to our Google Analytics setting variable in GTM.

alt_text

Publish the container and you’ll be good to go.

Conclusion

After capturing the GCLID, you can see and download the GCLIDs along with all your other GA data in a custom report like this one.

alt_text

If you’re using GA’s User-ID feature (and adding it as a custom dimension with GTM) you could associate offline conversions with GA and Google Ads data. You could download this data and add it to other reports.

You could also use GTM to automatically add the GCLID to your form submits or even your CRM.

The power is now in your hands.

comments powered by Disqus