Skip to main content
With this integration, you can initialize Twinalyze Analytics, enable automatic tracking, and send custom events from Google Tag Manager.

Overview

The Twinalyze GTM integration works like this:
Before you start, make sure you have:
  • A Twinalyze account
  • A Twinalyze project
  • API Key and Public Key
  • A Google Tag Manager account
  • GTM container access
  • Website code or admin access
Use only client-safe keys inside Google Tag Manager because GTM runs in the browser.

Install Google Tag Manager

First, add the Google Tag Manager script to your website.
1

Open your GTM container

Open Google Tag Manager and select your website container.
2

Copy GTM install code

Click your GTM container ID, such as GTM-XXXXXXX. Google Tag Manager will show two code snippets.
3

Add script in head

Add the first GTM script as high as possible inside your website <head> tag.
4

Add noscript in body

Add the second GTM noscript code immediately after the opening <body> tag.
5

Publish website changes

Save and publish your website changes.
Head script:
Body noscript:
Replace GTM-XXXXXXX with your actual Google Tag Manager container ID.

Initialize Twinalyze SDK

After GTM is installed, create the Twinalyze initialization tag.
1

Create new tag

In Google Tag Manager, go to Tags and click New.
2

Choose Twinalyze template

In Tag Configuration, select Twinalyze Web Analytics SDK.
3

Select Initialize SDK

In the Tag Type dropdown, select Initialize SDK.
4

Add project details

Enter your API Key, Public key, and API Base URL.
5

Enable tracking options

Enable the tracking options you need, such as page view, scroll depth, element click, form, site search, and file download tracking.
6

Add trigger

Select the All Pages trigger.
7

Save tag

Name the tag Twinalyze - Initialize SDK and save it.
Recommended setup:
The Initialize SDK tag should fire on All Pages. This makes Twinalyze available across your complete website.
Your Twinalyze project API Key. This connects website activity with your Twinalyze project.
Your Twinalyze project Public Key. This is used by the Web SDK while sending analytics data from the browser.
The API endpoint where Twinalyze events are sent.
You can enable page view, scroll depth, element click, form start/submit, site search, and file download tracking.
Add search URL parameters used by your website.
Add file extensions you want to track.
Enable debug mode while testing. Disable it before publishing to production.
SDK version example: 1.0.19

Track Custom Events

To track custom actions like add to cart, purchase, signup, or form submit, push an event into GTM dataLayer. Example website code:
Common event examples: Now create GTM variables, trigger, and tag.
1

Create Data Layer Variables

Go to Variables, create new Data Layer Variable entries, and use the exact keys from your dataLayer event.
2

Create Custom Event Trigger

Go to Triggers, create a Custom Event trigger, and enter the event name. For this example, use add_to_cart.
3

Create Twinalyze event tag

Go to Tags, create a new Twinalyze tag, select Track Event or your custom event option, and set event name as add_to_cart.
4

Map event properties

Map GTM variables as event properties, such as product_id, product_name, price, currency, and quantity.
5

Attach trigger

Attach your custom event trigger, such as CE - add_to_cart, to the Twinalyze custom event tag.
Recommended Data Layer Variables: Custom Event Trigger example: Twinalyze custom event tag example: Event property mapping:
Property nameGTM value
product_id
product_name
price
currency
quantity
Complete custom event flow:

Test and Publish

Test your setup before publishing.
1

Open GTM Preview Mode

In Google Tag Manager, click Preview and connect your website.
2

Check Initialize SDK tag

Visit your website and confirm that Twinalyze - Initialize SDK fires on page load.
3

Check custom event

Perform the action, such as clicking Add to Cart, and confirm that add_to_cart appears in GTM Preview Mode.
4

Check event tag

Confirm that Twinalyze - Add To Cart fires on the custom event.
5

Check Twinalyze dashboard

Open your Twinalyze dashboard and confirm that events are visible.
6

Publish container

Disable debug mode and publish your GTM container.
Production checklist:
  • GTM script is added to the website
  • Twinalyze Initialize SDK tag is firing
  • Initialize SDK trigger is set to All Pages
  • API Key is correct
  • Public key is correct
  • API Base URL is correct
  • Required automatic tracking options are enabled
  • Data Layer Variables are created correctly
  • Custom Event Trigger event name matches the dataLayer event
  • Twinalyze custom event tag is firing
  • Debug mode is disabled
  • GTM container is published
  • Events are visible in Twinalyze dashboard

Troubleshooting

Check that both GTM snippets are added correctly. The script should be inside <head> and the noscript should be immediately after <body>.
Check that the tag trigger is set to All Pages.
Check that the SDK URL is correct and allowed in template permissions.
Check that your website is pushing the event to window.dataLayer. The pushed event name must match the Custom Event Trigger name.
Check that Data Layer Variables use the exact same names as the keys pushed in dataLayer. For example, if dataLayer has product_id, the Data Layer Variable Name must also be product_id.
Check API Key, Public key, API Base URL, GTM publish status, Twinalyze tag firing status, and whether your website blocks the SDK CDN URL.
Make sure only one Twinalyze Initialize SDK tag is firing on the same page. Also check that your custom event is not pushed multiple times from your website code.