Skip to content

TikTok

This guide provides a step-by-step approach to setting up TikTok Pixel and the TikTok Events API (CAPI) using Google Tag Manager (GTM) and a server-side container. This "parallel tracking" method is the most robust way to ensure accurate and resilient data collection for your TikTok advertising campaigns.

Prerequisites

Before you begin, ensure you have the following:

  • TikTok Business Center: Access to the TikTok Ads Manager account, including the Events Manager for your specific Pixel.

  • Pixel ID and Access Token for the TikTok Events API, which can be obtained in TikTok Events Manager.

  • Web Google Tag Manager (GTM): Access to a web GTM container that is already implemented on your website and sends GA4 events to the server-side GTM. Learn how to share access to a GTM container here.

  • Server-side GTM Container: A server-side GTM container provisioned by  Usercentrics, available via a first-party endpoint, and configured to process GA4 events. Learn how to set up a server-side GTM provided by Usercentrics here.

Benefits of Server-Side Tagging for TikTok

  • Improved data accuracy: Server-side tagging bypasses ad blockers and browser privacy restrictions (like ITP/ETP), resulting in more reliable and complete conversion data.

  • Enhanced data control: You decide exactly what data to share with TikTok, allowing you to enrich or anonymize information to comply with privacy regulations (GDPR/CCPA). Shifting tagging from the browser to the server may also reduce the load on the JavaScript thread in the browser, improving site speed and Web Vitals, which can positively impact SEO.

  • Better attribution: With first-party cookies and more resilient event delivery, you can achieve more robust attribution for your TikTok campaigns.

Rollout plan

The implementation follows a parallel tracking model. This means you will send events from both the user's browser (via TikTok Pixel) and your server (via TikTok Events API). TikTok will then use a unique Event ID to deduplicate these events, ensuring that a single user action is only counted once.

Step 1: Implementation of Parallel Tracking

Part A: Web GTM (Client-Side) Configuration

The goal of this step is to configure your website's GTM container to send data to your new server container and to fire the standard TikTok Pixel for browser-side tracking.

Note

TikTok CAPI template in the server container, is compatible with the Google Analytics events sent to the server. Therefore, the following setup is based on Google Analytics being fired from the web container.

  1. Create a Unique Event ID Variable.

    For deduplication to work, every event must have a unique ID that is identical for both the browser and server event.

    1. In your Web GTM container, go to Variables - New.

    2. Choose Custom JavaScript Variable and paste the following code:

      function() {
        var timestamp = new Date().getTime();
        var randomNumber = Math.random().toString(36).substring(2);
        return 'evt_' + timestamp + '_' + randomNumber;
      }
      

    3. Name this variable CJS - Unique Event ID.

  2. Add Event ID to GA4 Event Tags.
    Add a parameter event_id and insert the {{CJS - Unique Event ID}} variable as a value on each GA4 event.

  3. Set Up the TikTok Pixel Tag.

    1. In your Web GTM container, go to Tags - New.

    2. Click Tag Configuration and find the TikTok Pixel tag template in the Community Template Gallery.

    3. Enter your TikTok Pixel ID. It's best practice to store this in a Constant variable.

    4. For the PageView event (and other standard or custom events), insert the {{CJS - Unique Event ID}} variable in the Event ID field.

    5. Set the trigger to All Pages for the base PageView tag. For other events (e.g., AddToCart, Purchase), use the appropriate triggers.

Note

The same triggers must be used for the TikTok and Google Analytics tags, to preserve the same event ID sent to the server container.

Part B: Server-side GTM (Server-Side) Configuration

Now, we will configure the server container to receive the data from the web container and forward it to TikTok's Events API.

  1. Set up the TikTok Events API tag:

    1. Go to Tags - New.

    2. Click Tag Configuration and search for the official TikTok Events API (Official) template.

    3. Enter the same Pixel ID you used in the web container.

    4. Generate Access Token in TikTok Events Manager under Events API settings. Create a variable in server-side GTM and provide it in the tag’s field.

    5. Event Name: Choose an event name from the list provided in the template (Purchase, AddToCart, etc.). As TikTok template is compatible with the Google Analytics events, you may as well select a built-in variable Event Name and it will be automatically transformed into the TikTok Standard Event name.

    6. Event ID: Map the event_id coming from GA4 (for deduplication).

  2. Configure Advanced Matching (recommended):

    In the TikTok Events API template, you can improve Event Match Quality by sending hashed user parameters:

    • SHA256 Hashed Email

    • SHA256 Hashed Phone

    • SHA256 Hashed External ID

      These should be collected from your GA4 data layer or other sources.

  3. Properties (Product Data):

    • Use GA4 e-commerce data layers (recommended if implemented).

    • Or use custom data mapping.

  4. Set up Triggering:

    You can explore an idea of allowlisting specific incoming events, which can be standard and custom. This way, you will minimize the risk of polluting the analytics with unwanted events and reduce the amount of data that you share with third-party vendors.

  5. Deduplication: Ensure the same event_id is passed from both web and server tags.

  6. Final result After the parallel tracking has been set up, you may need to wait some hours before the reported data from both the web pixel and the Conversions API become visible in the interface. Usually, you can expect a higher volume of server events surfacing in the reports. You may drill down on each event individually and verify that there are no abnormal discrepancies between the web and server events.

    Resulting data in TikTok Events Manager

Step 2: Quality assurance

Testing is critical. Use GTM's Preview mode and TikTok’s Test Events view simultaneously.

Part A: Validation and debugging

Follow these steps to validate your setup:

  1. Open Preview Mode: Start Preview mode in both your Web and Server-side GTM containers.

  2. Open TikTok’s Events Manager section, select the pixel and open the Test events tab.

TikTok - Test events tab

  1. Generate Traffic: Open your website from the GTM Preview tab. Navigate around and trigger the events you've set up.

  2. Verify in Web GTM: In the Web GTM Preview, you should see your TikTok’s Pixel tags firing. Click on a tag and inspect the Event ID being sent.

  3. Verify in server-side GTM:

    • In the server-side GTM Preview, you should see incoming requests from your GA4 client.
    • Click on the Facebook Conversions API tag that fired. Inspect the Event ID in the outgoing request to TikTok. It must match the Event ID from the Web GTM tag.
  4. Verify in TikTok Events Manager:

    • In the Test events tab, you should see the event activity.
    • Crucially, you will see events arriving from the browser pixel and the server. Both events must have the same event_id. This confirms your setup is working correctly.

TikTok - Test events tab

Part B: Expected challenges and solutions

Events not deduplicated or missing

Check that the exact same event_id is passed from both Web GTM (Pixel tag) and Server-side GTM (CAPI tag), and that the event names match TikTok’s whitelisted format. In Preview, confirm the event_id appears in both the browser request and the outgoing server request, and verify in TikTok Events Manager that events show as “Deduplicated” rather than duplicated or missing.

Low match quality

TikTok requires an email address to improve the match quality. Check that you pass a hashed value of the valid and normalized email address.

Error details about low EMQ

Server events missing

Check server-side GTM preview under Tags - Outgoing Requests for TikTok API error responses. You may also enable logging directly in the tag template.

  • Improve event match quality: Systematically go through your data layer and user information available on the site. Work with your developers to expose more non-PII and PII (to be hashed) data points that you can send via the Conversions API. The more high-quality data you provide, the better your ad targeting and attribution will be.

  • Block redundant browser-side beacons: Once you are confident in your server-side setup, you can consider blocking certain TikTok Pixel tags from firing in the browser for specific users or situations (e.g., for logged-in users where you have rich server-side data) to further improve site performance. This is an advanced step and should be approached with caution.