TikTok Events API for Server-Side Google Tag Manager (sGTM)
Here (opens in a new tab) is original source of TikTok for Business Developers
Learn about more TikTok Events here (opens in a new tab).
Get Started
This guide walks you through the process of setting up Web Events API through server-side Google Tag Manager.
Before you begin
You should already have set up Google Tag Manager server-side tagging. Specifically:
- Set up and install Google Tag Manager.
- A frontend tag (Google Analytics 4) sending events to the tagging server. Learn more about Google Analytics 4 (GA4) (opens in a new tab).
- Triggers (opens in a new tab) and variables (opens in a new tab) configured in your server-side container.
You should have access to TikTok Ads Manager that contains test event functionality and diagnostic tools that would help you during development testing and post integration validation.
- You must have created a pixel in the TikTok Ads Manager under Tools > Events.
- Once you create a pixel, you can send events via website through installing the pixel base code (opens in a new tab) or send events via Events API. The recommended best practice is to send both that would maximize your event coverage and campaign performance. Furthermore, with the dual channels setup, your campaign performance is protected against event disruption as the event signals will still come in from one channel when the other fails. If you are sending events from both Pixel SDK and Events API, you will need to set up event deduplication (opens in a new tab).
If you don't already have a pixel, start with the first step to create a pixel
If you already have an existing pixel, skip the first step and start with the second step.
- Create a Pixel in Events Manager
You'll need a Pixel ID and an API Access Token to use this template. This section will walk you through the process of creating a pixel in Events Manager.
If you have already had a pixel created, skip this step and jump to Step 2 Get Pixel ID & Events API Access Token (opens in a new tab).
(1) Go to TikTok Ads Manager (opens in a new tab).
(2) After logging in, hover over "Tools" on the navigation bar, and find "Management", then click on "Events".
(3) Click on the "Manage" button under "Web Events".
(4) Click on "Setup Web Events", fill in the pixel name and select "Events API", then click "Next".
(5) Select "Automatically Set Up Web Events via Partner Platforms", and click "Next".
(6) Choose "Google Tag Manager Server-side", then click on "Next".
(7) You now have a new pixel created for you. The pixel ID is displayed at this final step. You can also select the "Go to template" button to navigate to our Google Tag Manager's server template.
- Get Pixel ID & Events API Access Token
Both Pixel ID and Events API access tokens can be found by navigating to Tools > Events > Web Events > select a pixel > Settings tab.
(1) At the top, you will find your Pixel ID. Copy and save the Pixel ID.
(2) Scroll down to click "Generate Access Token". Copy and save the token information shown.
Now, you should have both your Pixel ID and Access Token. For example, they should look like the following:
- Pixel ID: CIB1R6JC77UCDSLJS0OG
- Access Token: 00c350fde1xxxxxxxxxxxxxxxxxxxxxxxx1991af
Set up Server-Side Google Tag Manager
=====================================
Install the Template
You can find TikTok's official template "TikTok Events API (Official)" template from the Google Tag Manager Community Template Gallery. Click "Add to workspace" to install it into your workspace.
Note that the template can only be applied to a Server container. Therefore, you need to ensure that the Container Type of your container is Server.
Use the Template
Back on Google Tag Manager, create a new Tag, then select the "TikTok Events API (Official)" template you just imported.
1. Event Configuration
Enter the Pixel ID and Access Token from the previous section.
You can make the Pixel ID and Access Token into Variables for easier reuse across tags. Click on the "+" sign beside each box to select from your Variables.
Select an Event you'd like this tag to send. The Event should depend on what trigger you decide to associate with this tag. To learn more about TikTok's available event types, see TikTok's Supported Pixel events (opens in a new tab).
2. Advanced Matching
In the next section, you can configure sending Email, Phone, and External ID to TikTok. All Email, Phone, and External ID are hashed (with SHA256) before they're sent to TikTok in order to preserve anonymity.
We recommend leveraging Advanced Matching where possible and early in the funnel for best results.
In the example below, two variables (opens in a new tab) defined by Google Tag Manager are used to fill out Email and Phone.
There are two options to pass the information:
3. Product Info, Enhanced - Standard E-commerce
The following section is your product information. This is important if you're advertising a product sold on a site. Sending the full product info enables measurement and optimization through solutions such as TikTok's Video Shopping Ads (VSA) for commerce, Value Based Optimization (VBO), or ROAS measurement.
Option 1 - Use Google Analytics Ecommerce Data Layers (Recommended):
The easiest way to set this up is through Google Analytics Ecommerce Data Layers. Whether you're using the Google tag (opens in a new tab) (gtag.js) or Google Tag Manager for GA4, as long as you're pushing product data to the data layer, the product information can be captured and sent automatically.
To learn more about Ecommerce Data Layers, see Measure ecommerce (opens in a new tab).
Option 2 - Use Custom Data:
Select "Use Custom Data", and use your Variables to fill out the rest of the form.
- Single Content: Associate this event with one product.
-
Multiple Contents: Associate this event with multiple products; the "contents" field must be filled with a JSON-encoded string of products.
For example:
[ { "price": 100, "quantity": 2, "content_id": "12345", "content_type": "product", "content_name": "Fancy-AirMax2.0 Black", "content_category": "Shoes - Running Shoes", "brand": "Fancy Sneakers" }, { "price": 40, "quantity": 1, "content_id": "45678", "content_type": "product", "content_name": "Fancy-AirMax2.0 White", "content_category": "Shoes - Running Shoes", "brand": "Fancy Sneakers" } ]
Read more (opens in a new tab) about the valid schema of the JSON object.
- Order Info Only: Only post back "value" and "currency" information to TikTok.
4. Deduplication
For the best ad performance, we recommend advertisers set up both TikTok Pixel SDK and Events API to ensure maximum data coverage.
Deduplication is needed for advertisers who are using both TikTok Pixel SDK and Events API to send the same event. If you are sending the same event from both TikTok Pixel SDK and Events API, then you need to set up deduplication with the Event ID. Doing so allows TikTok to deduplicate multiple copies of the same event, and would allow TikTok to better report/optimize your campaign performance. For details of Event deduplication, see here (opens in a new tab).
5. Other Configurations
The tagging server will automatically fill in information in this section. Feel free to leave this section blank, unless you wish to override any field.
6. Choose a Trigger
Choose a GTM Trigger to associate with the tag, then click "Save".
Test Server Tags
- Click "Preview" to test out the new Tag. You may need to trigger it from your GA4 installation.
- After triggering a Tag created with the "TikTok Events API (Official)" template, you can see the Events API call in the Console. Specifically, you should be able to see the API response body. When the response contains
{"code": 0, "message": "OK"}
, it means the request was sent successfully.
Verify setup
Verify that events are configured and triggered correctly through Test Events.
Steps
-
In Events Manager, click the pixel to view its configuration details.
-
In the Test Events tab, click the test code button in Step 2 of the Test Server Events section to copy the code.
- Fill in the "Test Event Code" field in the template. Then save the changes.
-
Follow "Test Server Tags (opens in a new tab)" steps from the previous section and trigger a test event.
-
Go to the Test Events tab of the pixel in Events Manager, and look for the test event in the Event Activity section. Any issues with the payload will show up to help you resolve the issues.
- Ensure the removal of test event code upon finishing up testing.
FAQ
Is server-side Google Tag Manager the right solution for me?
Situation | Recommendation |
---|---|
Google Tag Manager (GTM) users who set up TikTok pixel via GTM but have not set up Events API yet | Highly recommend setting up TikTok Events API via GTM Server Side template. |
Google Tag Manager (GTM) users who have not set up either TikTok pixel or Events API | Recommend setting up both Pixel and Events API via GTM templates. Utilizing both templates together streamlines the required and recommended parameter configurations. |
Google Tag Manager (GTM) users who set up Events API but not TikTok pixel | Recommend setting up TikTok pixel to achieve Pixel and Events API dual setup for best ads performance. |
Non-Google Tag Manager users | Read Google's related product page (opens in a new tab) to learn more and decide if you want to use Google Tag Manager. |