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: "".

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 -->
fbq('init', '{{LT - FB Pixel}}');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="{{LT - FB Pixel}}&ev=PageView&noscript=1"
<!-- 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 are currently not available due to roll out of custom built blog theme. I'm working on getting this available again, but in the mean time you can write to me on LinkedIn if you have any questions.

© Copyright - - 2018-2021