The Clerk.io tag template brings Clerk.io’s personalised search, recommendations, and audience tracking into Google Tag Manager with five action types: Initialize, Track Product View, Track Cart, Track Purchase/Sale, and Track Search. It loads clerk.js from Clerk’s CDN and uses the Clerk() command queue pattern via __clerk_q, so you can manage all Clerk.io tracking from GTM without custom HTML tags.
Features
- Five action types in one template: Initialize, Track Product View, Track Cart, Track Purchase/Sale, and Track Search
- Initialize action loads
clerk.jsfromhttps://cdn.clerk.io/clerk.jsand sets your API key - Configurable options for language locale and email collection (
collect_email) - Product View tracking sends product IDs to Clerk for behavioural profiling
- Cart tracking syncs the full cart state as an array of product IDs
- Purchase tracking logs order ID, product IDs, and optional customer email for post-purchase recommendations
- Search tracking captures search queries for Clerk’s search analytics
Installation
- In your GTM workspace, go to Templates > Tag Templates > Search Gallery.
- Search for “Clerk.io” and add the template.
- Create one Initialize tag for all pages, plus additional tags for each tracking action you need (product view, cart, purchase, search).
Field Reference
Initialize action
| Field | Type | Required | Description |
|---|---|---|---|
| Action Type | Dropdown | Yes | Select “Initialize”. |
| API Key | Text | Yes | Your Clerk.io public API key (found in your Clerk.io dashboard under Settings). |
| Language | Text | No | Language/locale code (e.g., en, da, nl) for multi-language stores. |
| Collect Email | Checkbox | No | When enabled, Clerk.io collects visitor email addresses for audience segmentation. |
Track Product View action
| Field | Type | Required | Description |
|---|---|---|---|
| Action Type | Dropdown | Yes | Select “Track Product View”. |
| Product IDs | Text / Variable | Yes | The product ID(s) being viewed. Can be a single ID or an array. |
Track Cart action
| Field | Type | Required | Description |
|---|---|---|---|
| Action Type | Dropdown | Yes | Select “Track Cart”. |
| Product IDs | Variable | Yes | An array of product IDs currently in the cart. |
Track Purchase/Sale action
| Field | Type | Required | Description |
|---|---|---|---|
| Action Type | Dropdown | Yes | Select “Track Purchase/Sale”. |
| Order ID | Text | Yes | Unique order/transaction identifier. |
| Product IDs | Variable | Yes | An array of product IDs in the order. |
| Text | No | Customer email address for post-purchase personalisation. |
Track Search action
| Field | Type | Required | Description |
|---|---|---|---|
| Action Type | Dropdown | Yes | Select “Track Search”. |
| Search Query | Text | Yes | The search term entered by the visitor. |
Configuration Guide
Step 1: Deploy the Initialize tag
Create a tag with Action Type set to “Initialize” and enter your API Key. Optionally set the Language if you run a multi-language store, and enable Collect Email if you want Clerk.io to capture visitor emails. This tag must fire on every page to load clerk.js from https://cdn.clerk.io/clerk.js and make the Clerk command queue available.
Step 2: Track Product Views
Create a tag with Action Type “Track Product View”. Map the Product IDs field to a Data Layer Variable that resolves to the current product ID on product detail pages. This sends a click event to Clerk.io for recommendation profiling.
Step 3: Track Cart State
Create a tag with Action Type “Track Cart”. Map Product IDs to a variable returning the array of product IDs currently in the cart. Fire this tag on cart update events (add to cart, remove from cart, cart page view) so Clerk.io always has an up-to-date view of the cart.
Step 4: Track Purchases
Create a tag with Action Type “Track Purchase/Sale”. Map Order ID and Product IDs to your order confirmation dataLayer variables. Optionally include the customer Email for post-purchase email recommendations.
Step 5: Track Searches
Create a tag with Action Type “Track Search”. Map Search Query to a variable containing the visitor’s search term. Fire this tag when a search is performed, typically on a search results page load or a custom search event.
Tag sequencing (recommended)
Use GTM’s Tag Sequencing feature to ensure the Initialize tag has loaded clerk.js before any tracking tags fire. Set the Initialize tag as a setup tag for your Product View, Cart, Purchase, and Search tags.
Triggers and Setup
| Tag | Trigger Type | Condition |
|---|---|---|
| Initialize | All Pages (Page View) | Fires on every page load |
| Track Product View | Page View or Custom Event | Fires on product detail pages |
| Track Cart | Custom Event | Fires on add_to_cart, remove_from_cart, or cart page |
| Track Purchase/Sale | Custom Event or Page View | Fires on purchase event or thank-you page URL |
| Track Search | Page View or Custom Event | Fires on search results page or search event |
dataLayer snippets
Push the following on your product detail pages:
dataLayer.push({
event: 'view_item',
clerk_product_ids: ['PROD-12345']
});
Push the following when the cart changes:
dataLayer.push({
event: 'cart_update',
clerk_cart_product_ids: ['PROD-12345', 'PROD-67890']
});
Push the following on your order confirmation page:
dataLayer.push({
event: 'purchase',
clerk_order_id: 'ORD-2024-001',
clerk_product_ids: ['PROD-12345', 'PROD-67890'],
clerk_email: '[email protected]'
});
Push the following when a search is performed:
dataLayer.push({
event: 'search',
clerk_search_query: 'blue running shoes'
});
Troubleshooting
clerk.js not loading
Verify the Initialize tag is firing on the page. Check the Network tab in DevTools for a request to https://cdn.clerk.io/clerk.js. If blocked, an ad blocker or content security policy may be interfering.
API key error in console
If you see authentication errors in the browser console, confirm the API Key in the Initialize tag matches the public API key in your Clerk.io dashboard (Settings > API Keys). Do not use the private key.
Product views not registering
Check in GTM Preview that the Product IDs variable resolves to the correct value on product pages. The value must match the product IDs in your Clerk.io data feed.
Cart sync out of date
The Track Cart action sends the entire cart state, not incremental changes. Make sure the Product IDs variable always returns the complete array of cart product IDs at the time the tag fires.
Purchases not appearing in Clerk.io dashboard
Confirm the Order ID is unique per transaction. Clerk.io deduplicates on order ID, so resubmitting the same ID will not create a new record. Also verify the Product IDs array is not empty.
Search queries not tracked
Ensure the Search Query variable returns the actual search string, not undefined or an empty string. Check that the trigger fires at the right moment (after the user submits a search, not on every page load).
Support
- Clerk.io Documentation: https://docs.clerk.io/docs/clerkjs-quick-start
- Clerk.io Dashboard: https://my.clerk.io/
- GTM Community Template Gallery: Search “Clerk.io” for template listing and version history
- GTM Help Center: https://support.google.com/tagmanager/