This guide walks you through setting up TikTok Pixel and the TikTok Events API (CAPI) using Google Tag Manager (GTM) alongside a Seers-provisioned server-side container. The setup follows a "parallel tracking" approach, the most reliable method for achieving accurate, resilient data collection for your TikTok advertising campaigns.
Prerequisites
Before getting started, confirm the following are in place:
- TikTok Business Centre: Access to your TikTok Ads Manager account, including the Events Manager for your specific Pixel.
- Pixel ID and Access Token: Required for the TikTok Events API. Both can be retrieved from your TikTok Events Manager.
- Web Google Tag Manager (GTM): A web GTM container already deployed on your website and configured to send GA4 events to your server-side GTM instance. Refer to Google's documentation on sharing GTM container access.
- Server-Side GTM Container (Seers): A server-side GTM container provisioned by Seers, accessible via a first-party endpoint, and set up to process GA4 events. Visit the Seers Get Started guide to configure your container.
Why Use Server-Side Tagging for TikTok?
Greater Data Accuracy
Routing data through your server rather than the user's browser bypasses ad blockers and browser privacy restrictions such as Safari's ITP or Firefox's ETP. This produces more complete and reliable conversion data reaching TikTok.
Stronger Data Control
You have full control over what information is shared with TikTok. This allows you to enrich, filter, or anonymise data to comply with regulations like GDPR and CCPA. Moving tracking server-side also reduces the JavaScript load in the browser, improving page speed, Core Web Vitals, and potentially your SEO performance.
Better Attribution
First-party cookies set from your own domain are more durable than third-party cookies, and server-side event delivery is more resilient to browser restrictions. Together, these lead to stronger, more consistent attribution for your TikTok campaigns.
Implementation Overview
This setup uses a parallel tracking model. Events are sent simultaneously from two sources: the user's browser via TikTok Pixel, and your server via the TikTok Events API. TikTok uses a unique Event ID to deduplicate these signals, ensuring each user action is counted only once, regardless of which source reported it.
Step 1: Parallel Tracking Implementation
Part A: Web GTM Configuration (Client-Side)
The goal of this step is to configure your web GTM container to forward data to your server-side container, while also firing the standard TikTok Pixel for browser-level tracking.
| Note: The TikTok CAPI template in the server container is compatible with Google Analytics events sent from the web container. The steps below assume Google Analytics is being fired from your web GTM container. |
Create a Unique Event ID Variable
For deduplication to work, every event must carry a unique ID that is identical across both the browser and server events for the same user action.
- In your Web GTM container, go to Variables and click New.
- Select Custom JavaScript Variable and paste in the following code:
function() {
var timestamp = new Date().getTime();
var randomNumber = Math.random().toString(36).substring(2);
return 'evt_' + timestamp + '_' + randomNumber;
} |
- Name this variable CJS - Unique Event ID.
Add the Event ID to Your GA4 Event Tags
On each GA4 event tag in your web container, add a parameter named event_id and set its value to the {{CJS - Unique Event ID}} variable.
Set Up the TikTok Pixel Tag
- In your Web GTM container, go to Tags and click New.
- Click Tag Configuration and search for the TikTok Pixel tag template in the Community Template Gallery.
- Enter your TikTok Pixel ID. It is best practice to store this in a Constant variable for easy reuse.
- For the PageView event, and any other standard or custom events, insert the {{CJS - Unique Event ID}} variable in the Event ID field.
- Set the trigger to All Pages for the base PageView tag. For other events, such as AddToCart or Purchase, apply the appropriate event-specific triggers.
| Important: The triggers used for your TikTok Pixel tags must match exactly the triggers used for your corresponding Google Analytics tags. This ensures the same Event ID is shared between the browser and server events. |
Part B: Server-Side GTM Configuration
Next, configure the server container to receive incoming data from the web container and forward it to TikTok's Events API.
Set Up the TikTok Events API Tag
- In your server-side GTM container, go to Tags and click New.
- Click Tag Configuration and search for the official TikTok Events API (Official) template.
- Enter the same Pixel ID you used in the web container.
- Generate an Access Token in TikTok Events Manager under Events API settings. Create a variable in your server-side GTM container and provide the token value there.
- For Event Name, either choose a specific event from the list in the template (e.g., Purchase, AddToCart), or select the built-in variable Event Name; the template will automatically map incoming GA4 event names to the corresponding TikTok standard event names.
- For Event ID, map the event_id field from the incoming GA4 data. This is essential for deduplication.
Configure Advanced Matching (Recommended)
To improve Event Match Quality, configure the tag to send hashed user parameters. These should be sourced from your GA4 data layer or other available data sources:
- SHA256 Hashed Email
- SHA256 Hashed Phone
- SHA256 Hashed External ID
Map Product Data (Properties)
- Use GA4 e-commerce data layers where available. This is the recommended approach if you have e-commerce tracking implemented.
- Alternatively, use custom data mapping to pass product-level information.
Configure the Trigger
- Set the trigger to fire on all GA4 client events.
- Ensure consent is validated at the trigger level, in line with Seers' consent guidelines.
- Consider allowlisting only the specific events you want to forward to TikTok, both standard and custom. This reduces noise in your analytics and limits the volume of data shared with third-party vendors.
-
Confirm that the same event_id is being passed from both the web Pixel tag and the server-side CAPI tag to ensure proper deduplication.
| Note: After parallel tracking is live, it may take several hours before data from both the web Pixel and the Events API becomes visible in TikTok's reporting interface. Server-side events will typically show a higher volume than browser events. Review each event individually and check for any unexpected discrepancies between web and server data. |
Step 2: Quality Assurance
Testing is a critical part of this setup. Use GTM's Preview mode alongside TikTok's Test Events view to validate your implementation before going live.
Part A: Validation and Debugging
- Open Preview Mode in both your Web GTM and server-side GTM containers.
-
In TikTok Events Manager, select your Pixel and open the Test Events tab.
- Load your website from the GTM Preview tab and navigate around to trigger the events you have configured.
- In the Web GTM Preview, confirm that your TikTok Pixel tags are firing. Click on a tag and check the Event ID being sent.
- In the server-side GTM Preview, verify that incoming requests from your GA4 client are visible. Click on the TikTok Events API tag that fired and inspect the Event ID in the outgoing request to TikTok; it must be identical to the Event ID sent from the web GTM tag.
-
In TikTok Events Manager under the Test Events tab, confirm that events are arriving from both the browser Pixel and the server. Both events must share the same event_id; this confirms your deduplication is working correctly.
Part B: Common Challenges and Solutions
Challenge: Events Are Not Being Deduplicated or Are Missing
Solution: Verify that the exact same event_id is being passed from both the Web GTM Pixel tag and the server-side CAPI tag, and that the event names match TikTok's accepted format. Use Preview mode in both containers to confirm the event_id appears in both the browser request and the outgoing server request. In TikTok Events Manager, check that events are marked as "Deduplicated" rather than appearing as duplicates or missing entirely.
Challenge: Low Event Match Quality
Solution: TikTok requires a valid email address to improve match quality. Ensure you are passing a properly hashed and normalised email address value with your events. Review your data layer to confirm this value is available and being correctly mapped in the tag configuration.
Challenge: Server Events Not Appearing in TikTok
Solution: Open the server-side GTM Preview mode and navigate to Tags, then check the Outgoing Requests section for any TikTok API error responses. You can also enable logging directly within the TikTok Events API tag template to get more detailed diagnostic output.
Step 3: Final Optimisations (Optional but Recommended)
Improve Event Match Quality
Conduct a systematic review of your data layer and the user information available across your site. Collaborate with your development team to expose additional data points, both non-PII and hashed PII, that can be passed through the Events API. The richer the data you provide, the more effective your ad targeting and attribution will be on TikTok.
Reduce Redundant Browser-Side Tracking
Once you are confident in the reliability of your server-side setup, consider suppressing certain TikTok Pixel tags from firing in the browser for specific users or scenarios, for example, for logged-in users where detailed server-side data is already being captured. This can further improve site performance by reducing client-side JavaScript execution. This is an advanced step and should be approached carefully to avoid unintended gaps in your tracking coverage.