
GTM Tag Template: Ad Click ID Storer (v1.0)
Want to run a leaner site by removing bloated ad platform pixels but still need click IDs for server-side CAPI? This lightweight template captures those IDs directly from the URL and stores them as rich JSON objects, ensuring your Conversion API events get the reliable attribution click ID data they need.
What does it solve?
The idea is simple. You've spent your marketing budget on serving ads. A user clicks, lands on your site with a lovely Click ID in the URL like gclid or fbclid, and then you ping an event or 'conversion' back into the black-box ad platforms to let them know what happened with said Click ID. This tells them to do more like that, or whatever magic they claim to do with that data.
But what if after clicking on your ad, they click to another page - that precious click ID vanishes into the digital ether.
The ad platforms try to solve for this by getting us all to add their code (i.e. tag or pixel) to all pages of our website, so that they can set cookies on our behalf to store their (and only their) Click ID. So when you fire their conversion in server-side GTM (i.e. CAPI tags), you can read their cookie(s) to get the Click ID.
But doing this opens up two issues:
- Adblockers and/or browsers interfere with these cookies as they are easily identifiable, and thus blockable.
- The code they provide to do this is often bloated and full of other 'stuff' that we don't want or need.
When implementing an ad platform's tracking, they all say to implement their Pixel (cGTM tag) and CAPI (sGTM tag). But they actually don't need both, they only need CAPI, assuming we can collect and provide their Click ID with it, we actually don't need the Pixel at all.
Rather than this being a big dev/engineering project, I’ve cooked up a Google Tag Manager tag template, the Ad Click ID Storer, to solve this very problem. It’s soon to be live in the GTM Community Template Gallery, but for now, you can access and use it on GitHub here.
What does it do?
At its core, the template captures advertising click IDs from URL query parameters (gclid, fbclid, msclkid, and all the other usual suspects) and stores them in a first-party cookie.
"Big deal," I hear you say, "other scripts do that." But here's the clever bit (if I do say so myself) - it doesn't just save the latest value as a simple string. It creates a rich JSON object for each parameter, packed with useful context.
This is what gets stored for each Click ID it finds:
- value: The actual Click ID itself.
- count: A running tally of how many times the user has arrived with the parameter in the URL. Note that this increments even if the value is the same.
- datetime: A precise timestamp of the last time it was captured.
- location: The full URL the user landed on.
- referrer: The URL of where they came from.
- previous_values: An optional array of the five most recent previous values for that ID.
Below is an example of the JSON in the cookie (and local storage backup):
{
"gclid": {
"value": "Cj0KCQjwmICoBhDxARIsABXk",
"count": 5,
"datetime": "2025-05-11T09:32:51.423Z",
"location": "https://yourwebsite.com/product?gclid=Cj0KCQjwmICoBhDxARIsABXk",
"referrer": "https://google.com/",
"previous_values": ["abc-123","xyz-987"]
},
"fbclid": {
"value": "abc123-987zyx",
"count": 1,
"datetime": "2025-10-14T12:30:15.123Z",
"location": "https://yourwebsite.com/blog?fbclid=abc123-987zyx",
"referrer": "https://facebook.com/",
"previous_values": []
}
}
How does it work?
This template is designed to be both powerful and flexible, without you having to write a single line of code.
- Built-in Ad IDs: It automatically looks for over 15 common Click IDs listed below. You can also add any custom query string parameters you need on top.
gclid,gbraid,wbraid, andgad_campaignid- Googlefbclid- Facebook/Metamsclkid- Microsoft/Bingttclid- TikToktwclid- Twitter/Xli_fat_id- LinkedInawc- Awinsccid- Snaprdt_cid- Redditspclid- Spotifyqclid- Quoraepik- Pinterestadct- AdRollob_click_id- Outbrain (this is the suggested param, but is manually defined)tbclid- Taboola (this is the suggested param, but is manually defined)
- (Optional) Dual Storage: It uses a first-party cookie but also backs everything up to localStorage. If one gets cleared, the other one repopulates it. This maximises the chance of your data sticking around.
- (Optional) DataLayer Push: With a simple tick box, you can push the entire JSON object to the dataLayer on every page. This makes it instantly available for other client-side GTM tags to send off to GA4, ad platform conversions, or your own backend systems.
- (Optional) Intelligent Logic: You can choose to ignore updates from blank or self-referrals, preventing your data from being overwritten by internal navigation.
- (Optional) Historical Tracking: Optionally store the five most recent previous values for each Click ID to get a clearer view of multi-touch journeys from the same channel. Useful to improve the chances the ad platform can recognise the click for attribution.
How do I set it up in cGTM?
Getting it set up is dead simple, or it will be. When it eventually releases on the community gallery, you will be able to follow these steps:
- In Google Tag Manager, navigate to Templates and click Search Gallery.
- Search for "Ad Click ID Storer" or Kickflip Analytics.
- Find the template, then click Add to workspace and accept the permissions.
- Go to Tags > New, select the template, and configure the settings to your liking.
- Set it to fire on your main page view trigger (e.g., 'All Pages' or a custom event like page_view for SPAs).
- Save, preview, and publish. Job done.
But for now, you can grab the template ( as well as a pre-configured container file) from the GitHub repository.
So, stop letting valuable attribution data slip through your fingers. Give the template a whirl, get a clearer picture of your user journeys, and make your server-side tracking that much more robust.
How do I use it in sGTM and CAPI?
1. Extend the cookie lifetime
Use the Cookie Extender tag sGTM tag template from Stape to extend the lifetime of the ad_click_id_store cookie (or whatever you name it). Especially relevant for Safari and Firefox browsers which restrict most marketing/analytics cookies to 1-7 days by default. This step is optional, but recommended.
Here you can see that I have set the ad_click_id_store cookie to 30 days (2592000 seconds):

2. Set up your sGTM variables
Here you can use the Extract From JSON sGTM variable template from the gallery to easily grab any element from the cookie.
Here you will need to pass in an existing variable for the whole cookie value, which I have called {{Cookie - ad_click_id_store}}, and in this example I'm pulling the most recent gclid value:

3. Pass the Click IDs into your sGTM tags
Now that the Click ID values are available as variables in sGTM, it's a simple process of using them in your conversion tags (CAPI or otherwise).
Here I'm using Stape's TikTok CAPI tag template and passing in the ttclid into the 'ttclid' User Data field:
