Secret to Setup Facebook Pixel Tracking Correctly in Google Tag Manager

Video Transcript

Do you know………….most likely…………..your Facebook Pixel tracking in Google Tag Manager……… is not set up correctly…..and it is costing you money…..


I am Himanshu

And today i am going to show you…………how to setup Facebook Pixel Tracking Correctly when using Google Tag Manager.

You probably know that……..Google Tag Manager…..doesn’t play well with Facebook.

For example, the Facebook JavaScript SDK code can not be deployed via GTM.

This is the SDK code you need……if you want to use a Facebook plugin like….. Facebook Like button…. Or Facebook Follow button.

This is the code you need….if you want to track Facebook Social Interactions like: ‘Facebook Likes’.

While you may not be able to deploy the Facebook SDK code via GTM, you can still deploy the Facebook default pixel code via GTM.

I have got an article on setting up Facebook pixel tracking via GTM: Learn to setup Facebook Pixel Tracking via Google Tag Manager

So I won’t be sharing the A to Z details of……how to set up the Facebook pixel tracking…..

What I am going to share with you… that one little tweak….that one secret…..which can make world of difference….

I have noticed that…… when you fire facebook pixel via GTM, facebook record hits from the domain .

You can confirm that by checking your pixel data in Facebook.

From your Power Editor or Ads Manager,……whatever you use, click on the ‘Pixels’ link:

Then click on the ‘Details’ button:

Now click on the ‘Activity’ tab:

Here you can see the list of all the events recorded by Facebook.

Lets click on the ‘Purchase’ event:

Now look at the Referring URLs column on the right hand side:

Can you see…. as the referring URLs?

Hits from this domain…. is inflating my purchase event pixel data.

Now this is really bad because Facebook machine learning algorithm uses the pixel data to optimize my Facebook campaigns for conversions.

And if the machine learning algorithm is going to get the corrupted pixel data ………….then how on earth……it will be able to find the audience………..who are most likely to make a purchase on my website.

So we need to stop the Facebook pixel from firing……..whenever the current URL contains and whenever the referrer is

You can do that by modifying the Facebook pixel code in such a way………….. that it fires only when the following condition is true:

For example, following custom HTML tag is used to fire the default pixel code:

Here you can see the additional line of code….added at the top…..which checks………whether the current URL contains and whether the referrer is………If yes then do not fire the facebook pixel code.

Use this same additional code for tracking all Facebook events like ‘add to cart’, ‘purchases’ etc:

For example this one is for ‘add to cart’ tag:

Here also you can see the additional line of code….added at the top…..which checks………whether the current URL contains and whether the referrer is………If that is the case… then do not fire the ‘add to cart’ event code.

All right.

That’s all for now.

See you soon.

Take Care. Bye!

Related Articles


What is the difference between Digital Analytics and Google Analytics?

99.99% of course creators themselves don’t know the difference between Digital analytics, Google Analytics (GA) and Google Tag Manager (GTM).

So they are teaching GA and GTM in the name of teaching Digital analytics.

They just copy each other. Monkey see, monkey do.

But Digital analytics is not about GA, GTM.

It is about analyzing and interpreting data, setting up goals, strategies and KPIs.

It’s about creating strategic roadmap for your business.

Digital Analytics is the core skill. Google Analytics is just a tool used to implement ‘Digital Analytics’.

You can also implement ‘Digital analytics’ via other tools like ‘adobe analytics’, ‘kissmetrics’ etc.

Using Google Analytics without the good understanding of ‘Digital analytics’ is like driving around in a car, in a big city without understanding the traffic rules and road signs.

You are either likely to end up somewhere other than your destination or you get involved in an accident.

You learn data analysis and interpretation from Digital analytics and not from Google Analytics.

The direction in which your analysis will move, will determine the direction in which your marketing campaigns and eventually your company will move to get the highest possible return on investment.

You get that direction from ‘Digital analytics’ and not from ‘Google Analytics’.

You learn to set up KPIs, strategies and measurement framework for your business from ‘Digital analytics’ and not from ‘Google Analytics’.

So if you are taking a course only on 'Digital Analytics’, you are learning to use one of the tools of ‘Digital analytics’. You are not learning the ‘Digital analytics’ itself.

Since any person can learn to use Google Analytics in couple of weeks, you do no get any competitive advantage in the marketplace just by knowing GA.

You need to know lot more than GA in order to work in digital analytics and marketing field.

So what I have done, if you are interested, is I have put together a completely free training that will teach you exactly how I have been able to leverage digital analytics to generate floods of news sales and customers and how you can literally copy what I have done to get similar results.

You can sign up for the free training here:

I truly hope you find it helpful.  

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

Himanshu Sharma

Digital Marketing Consultant and Founder of

Himanshu helps business owners and marketing professionals in generating more sales and ROI by fixing their website tracking issues, helping them understand their true customers purchase journey and helping them determine the most effective marketing channels for investment.

He has over 12 years experience in digital analytics and digital marketing.

He was nominated for the Digital Analytics Association's Awards for Excellence.

The Digital Analytics Association is a world renowned not-for-profit association which helps organisations overcome the challenges of data acquisition and application.

He is the author of four best-selling books on analytics and conversion optimization:

error: Alert: Content is protected !!