How to add a Facebook Conversion Pixels through Google Tag Manager

Facebook Pixel in Google Tag Manager

The right way to implement Facebook Pixel through Google Tag Manager

Facebook Conversions Pixels are great tools not just to monitor website or mobile apps conversions – those can also be controlled through after tagging URLs – but they are also one of the tools needed to optimise campaigns (e.g. cost per conversion) or to build Lookalike audiences (see image below) that tend to reduce your spending on Facebook advertising by creating target audiences made of users whose interests are similar to the ones of whoever has already reached a goal relevant to your business. On average I have noticed a conversion rate always higher than other generic audiences, sometimes even double.

Facebook Lookalike Audiences

To implement Facebook Conversion Pixels (FBCP) you have to create it for a particular Ads account activated in your site and populated with users info (it is said that you need at least 100 conversions to build a lookalike audience list). Once created it can be shared with other Ads Accounts and it can work for different Facebook Pages managed through the same Ads Accounts.

Google Tag Manager makes possible to add Conversion Pixels whenever and wherever you need, into any web page or mobile apps, depending on specific conditions. The Conversion Pixel has to be placed into the HEAD of your web page but, as you know, Google Tag Manager (GTM), has to be placed immediately after the opening BODY tag.

The question is: will Facebook Pixel works if implemented through a GTM Custom HTML tag?

The answer is yes! After implementing FBCP, you can check if it is working using the FB Pixel Helper, a free extension for Google Chrome.

Facebook Pixel inserted through Google Tag Manager is working (source: FB Pixel Helper, Google Chrome free extension)

Facebook Pixel inserted through Google Tag Manager is working (source: FB Pixel Helper, Google Chrome free extension)

NOTE – However, I have noticed that if “support for Document.Write” is not active for the HTML tag, the FB Pixel apparently takes longer to load – however, it still work – and the result is as follow:

GTM support document.write off

GTM support document.write off: FB Conversion Pixel takes too long to load

Subdomain

Tidy up your subdomain and multidomain web metrics with Google Tag Manager

Subdomain

SITUATION Let’s suppose that you have two sites to track, a main site and its subdomain

  • www.mysite.xyz
  • thirdlevel.mysite.xyz (for example it can be a specific product minisite or an ecommerce platform, a campaign landing page, etc.)

OBJECTIVE You want to monitor both all visits under one main Google Analytics profile (now called view) and also each single site separately. So you are planning to have at least three GA views.

PROCEDURE A standard way to distinguish pages after multidomain tracking can be made through a view where the hostname is added to the URI: this way pages will be distinguished by their hostname (normally absent on GA) as follows:

  • www.mysite.xyz/index.php
  • thirdlevel.mysite.xyz/index.php
  • etc…

Here is an alternative approach through Google Tag Manager:

1. Create a GTM container for the whole web property

2. On the container create two different GATC tags, each bringing data to the same GA property ID (UA-xxxxxxxxx-x). You can call GATC-main and GATC-third-level (you can use spaces if you like)

3. Mind the Rules! Each GATC tag need to have a Rule that activate it only when the visitor is on the relative site. For example, GATC-third-level tag will have the following rule:

GTM Rule

The Rule fire the tag only when the visitor is on the thirdlevel domain

4. Now just one more step – the most important – add a virtual page to GATC-third-level:

4.1 Before doing that create a Macro called path (or any other name) to collect URL / Path

GTM URL Path Macro

Add a URL Path Macro on GTM

4.2 Then add it to the Virtual Page Path

GA virtual page path gtm

Collect subdomain metrics under a virtual folder on GA through GTM

PLEASE NOTE – If you don’t follow this step, your pageviews will merge together when having the same name (e.g. index.php pageviews from the main domain will be summed up to index.php pageviews from the subdomain). You can still create separate profiles (views) for each site using a filter that distinguish traffic to the hostname (e.g. mysite vs thirdlevel.mysite) but you will not be able to have the whole view under one profile (mysite + thirdlevel.mysite but differentiated with a virtual folder).

5. change the Rule TO GATC-main tag in order to activate it only when the visitor is on your main domain (not the third-level); no need to add Virtual Page Path to GATC-main tag.

6. Now let’s move from Tag Manager to Analytics and add two more Views to your web property. The default view will collect all metrics (main domain and third-level) whilst two more will be for each site separately.

6.1 You just have to create a new view, e.g. “Main site only” and Filter out all visits that starts with subfolder “/yoursiteonthirdlevel/”

6.2 For the other view “Third-level only” instead the FIlter has to include only subfolder starting with “/yoursiteonthirdlevel/” as shown above:

filter-subdomain

Apply a filter to your subdomain GA View

Done!

PROCEDURE FOR MULTIDOMAIN TRACKING The same procedure is valid also for multidomain tracking

  • mysite1.xyz
  • mysite2.xyz
  • subdomain.myxite2.xyz
  • etc.

CROSSDOMAIN Don’t forget to add also crossdomain tracking following the procedure suggested by Google to let cookies move across all your funnel. If you don’t take this step, you will not be able to measure campaign performance attributing value to each digital marketing channel. Good luck!