Linus Larsson

Adding Facebook pixels for multiple markets with only one tag

Are you tired of having multiple tags in your GTM for Facebook pixels in different markets? If you have a domain with different markets as subfolders (e.g. ".com/de") then you probably are using one pixel tag for each market, i.e. if you have 8 markets on your domain then you use 8 different tags to fire your pixels. This is a common setup but wouldn't it be nice to clean up your container and instead only use ONE tag? To do this you will have to use some new variables.

Step 1

Create a constant variable for each market you will target. The variable should be set to the pixel ID for that specific market (see image below).

Your list of variables should look something like this:

Step 2

Okay, so now we have stored the pixel IDs in constant variables (maybe you had already done this?). The next step is to replace the triggers from your current tags to some sort of function that can decide what variable to send to the global tag and when. The easiest way to do this is by using a Lookup table or RegEx table depending on what logic you have implemented in the Data Layer. If you are using a variable (let's call it 'market') to let you know which market a page belongs to then you can use a Lookup table. If you haven't implemented this then you really should do that because let's face it, it's best practice! But if you simply can't get this to work because of some kind of limitation then I'll show you the other way to do it as well.

With the Data Layer:

Just make sure to use the corrct values that you send to GTM with your market variable.

Without the Data Layer:

Make sure that the RegEx matches the URL structure that you are using for your markets. In this case the URLs would be set in this way: "https://domain.com/market/".

Step 3

So now we have the logic in place to send the correct ID to the global tag. Now let's create the actual tag. Create a new custom HTML tag and copy the following code into it:

<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '{{LT - FB Pixel}}');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id={{LT - FB Pixel}}&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->

Notice that instead of adding the pixel ID we are adding our newly created variable (in this case "LT - FB Pixel"). This means that the tag will dynamically change the ID depending on the conditions you set up in the variable, so if the visitor is on the German market pages then the German pixel ID will be added to the global pixel tag. Make sure you only allow the tag to fire once per page and set the trigger to fire on all pageviews.

NOTE: If you want to add event tracking to your Facebook Pixels then you only have to add the code in a new custom HTML tag and make sure that you fire the tag above before the event tag. The Pixel ID will be set by the above tag, which means that you only have to create ONE tag per event that will work for all markets!

Comments

  1. Sylvia

    2018-05-28 03:31

    Hi Linus – Thank you for this informative article! I’m wondering what is the advantage of creating different domains for each market/location (with 1 tag in GTM as you’ve outlined above) versus just using UTM links for each country’s campaign? Thanks again.

  2. test test

    2019-02-15 08:03

    I regx table for FB event and i dont know why Pixel helper say your event fire multiple time

    • Linus

      2019-02-15 12:32

      Have you set the tag to only fire once per page?

  3. Morgan

    2019-03-12 17:58

    When viewing the tag in Preview mode – is it anticipated to see {{LT – FB Pixel}} as “undefined” or should it display the FB pixel id per the variable set?

    • Morgan

      2019-03-12 18:30

      Nevermind! Found my issue 🙂

  4. Gašper

    2022-07-13 09:02

    I don’t think setting up different pixels for different markets is a good idea. Segmentation is available per country and with splitting pixels you split data and extend pixel learning.

    • Linus Larsson

      2022-07-13 11:44

      Hi Gašper,
      I actually agree with you, but sometimes companies prefer to have separate pixels due to organizational reasons. The post is only a guide for how to install it if needed, not a recommendation of how to work with pixels from Facebook overall.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Cookie Settings

© Copyright - Lynuhs.com - 2018-2024