August 1, 2021
How to Implement Twitter Pixel with Google Tag Manager
Updated: August 1st, 2021
By implementing Twitter Pixel you can grow your remarketing (a.k.a. Tailored) audiences and show ads for them in particular. Even though 3rd party cookies will eventually die (because of the changing landscape in the ad tech industry), you can still use them to some extent at the moment.
In case you’re not familiar with Twitter remarketing, it works similarly to Google Ads Remarketing or Facebook Pixel, where a visitor lands on your website and gets a unique cookie (stored in his/her browser). That cookie enables Twitter to automatically recognize that person and retarget him/her with ads.
Google Tag Manager makes it easy for you to add a Twitter Universal Website tag (a.k.a. Twitter Pixel) in order to start growing a custom audience.
Before you continue
This blog post assumes you have a working knowledge of Google Tag Manager tags. If you’re a beginner – I highly recommend checking out these free Google Tag Manager courses, first. The minimum requirements are:
- You have a Google Tag Manager tracking code installed on your website.
- You know what tags, triggers, variables, and dataLayer are and how they work in Google Tag Manager.
P.S. This blog post is a part of a more comprehensive guide – Google Tag Manager + Twitter, so if you’re looking for more in-depth information about how to upgrade your Twitter marketing with Google Tag Manager, give it a try.
Get Twitter Pixel ID
First, you’ll need to log in to your Twitter account, and on the left side click More > Twitter Ads.
When you reach your Twitter Ads, click Tools and select Conversion Tracking. If you haven’t set any conversions before, you should see the following message:
As you can see in the screenshot above, the status of the Universal website tag is unverified. That will change once you implement the pixel, send some data, and wait for ~24 hours.
Click the View code and installation instructions under that tag status and you will get the pixel code. A sample code of Twitter Tracking Pixel will look like this:
Since Google Tag Manager provides a ready-made Twitter tag, all you need is Twitter Tracking Pixel ID. You can find it here:
Copy it. This ID is required in every Twitter Tag in GTM – just like every Google Analytics tag requires GA Tracking ID (UA-XXXXXX-XX) or measurement ID (G-XXXXXXXXX). Let’s create a constant variable for Twitter Pixel ID (because we’ll use it at least several times).
In Google Tag Manager, go to Variables and create a new user-defined variable:
- Title – Constant – Twitter Pixel ID.
- Type – Constant.
- Value – Paste Twitter Pixel ID, e.g. aa1x2.
Now open your Google Tag Manager account and create a new tag:
- Tag type – Twitter Universal Website Tag (you will need to use the search feature in the tag template list)
- Paste Twitter pixel ID.
- Select Tag Event – Pageview.
- In the Triggering section choose – All pages.
Test the tag
In the top right corner of the GTM interface, click Preview.
A popup there will ask you to enter the URL which you want to test and debug. It might be the address of a homepage or it might be a specific page’s URL and then press Start.
A new browser tab (or window) should appear where you will see the URL that you entered in the previous popup. If the page does not work, try to enable the preview mode once again an then disable this checkbox in the preview’s popup:
At the bottom of that page/tab, you must see the following badge:
And if you go back to the tagassistant.google.com tab, you must see this success message. Click Continue.
If you don’t see the success message or if the preview badge shows that the debugger is not connected, read this.
On the left side of the preview mode click on Container Loaded. This is an event that is equivalent to the All Pages or Pageview trigger. Once you do that, you should see that your Twitter Pixel tag has successfully fired.
Additionally, use the Twitter Pixel Helper Chrome extension. Install it. Refresh the page of your website where the preview mode is enabled and Twitter Pixel is activated.
Click the Twitter Pixel Helper icon in your Chrome browser. You should see something like this:
There will be a number next to the Twitter Pixel Helper icon. And also you will see that your website tag fired successfully.
Done! You have installed the Twitter Pixel tag. From now on, all visitors of your website will receive a 3rd party cookie from Twitter, thus your remarketing audience (a.k.a. Tailored audience) will grow. When those visitors with cookies browse Twitter, they’ll see your ads.
Don’t forget consent
I used the All pages in this blog post trigger for sake of simplicity. In reality, the setup is much more complex because you should fire tags like this one only if a visitor gives consent for tracking. To do that, you will need to:
- Have a cookie consent popup on your website
- Then configure GTM to listen to user interactions with that popup
- And then fire tags only if a visitor gives consent
Things to keep in mind
- It may take up to 24 hours for data to appear in a Twitter Ads account (but usually it’s processed much faster).
- Test, test, test before publishing – the devil is in the detail. One tiny mistake can lead to huge problems.
I will not go into details on how to set up the actual ad campaign on Twitter. You can watch this video instead.
Conversion tracking with Twitter Pixel
The next logical step would be to learn how to track conversions with Twitter Pixel. A conversion is an important event for your business. When you drive traffic to a website from Twitter ads, it is very important to measure which ads/campaigns are driving better results (read more conversions).
This can be done with conversion tracking and you can learn how to do that here (it’s an old-ish video but should still provide value).
That’s it! You have successfully installed a Twitter tracking pixel with Google Tag Manager. It’s actually a pretty easy thing to do but very powerful. Having pixel installed on your website will enable you to grow remarketing lists and show ads to them in particular.
This blog post is a part of a more comprehensive guide – Google Tag Manager + Twitter, so if you’re looking more in-depth tutorial about how to upgrade your Twitter marketing with Google Tag Manager, give it a try.
Did I miss something in this blog post? If yes, let me know in the comments!