How to Delay the Facebook Pixel with Google Tag Manager

In this guide, we’ll show you how to build higher quality audiences in your Facebook Ads by delaying your Facebook Pixel and eliminating bounced users from your audience.

This tutorial will explain:

Why Should You Delay the Facebook Pixel?

Delaying the Facebook Pixel from firing immediately when a user enters your website will filter out any user who isn’t really interested in what you have to offer.

Sometimes users click on links accidentally, or click a link thinking it contains different content than it actually does. These users typically leave the website immediately (we call this a “bounce”).

This is totally fine—not everyone on the whole internet is part of your intended audience. However, it could be a problem if these users become part of your targeted audience for marketing campaigns.

These users are not promising leads, and it could be a waste of your resources to target them. Instead, you should focus your efforts on users who are genuinely interested in your website or business.

If you want to optimize your audience for retargeting purposes, you might want to focus on users who have been on your website for more than a few seconds.

We can implement such a delay with the help of Google Tag Manager and create a Facebook audience of people who have stayed at least five seconds on your webpage.

Delaying your Facebook Pixel will give you a better quality audience by excluding those who have clicked on a link by mistake, or just closed the page immediately and didn’t have the chance to even look at the page.

Then, you should hopefully get better results by advertising to a better quality audience.

🚨 Note: If you use The Facebook Pixel and haven’t integrated Google Tag Manager yet, be sure to check out our Facebook Pixel Tracking with GTM guide.

Creating Your Base Facebook Tag

Let’s begin by creating our base Facebook Tag. This Tag will load the Facebook Pixel library so your pixel can record other Facebook events.

For this, let’s create a new custom HTML tag in Google Tag Manager. 

To create a new Tag, click on Tags, then New.

Create a new Tag in GTM

Make sure to give your Tag an informative name. I like to use CHTML for “custom HTML” to describe the Tag type, then the tool and the scope or function of the Tag. In this case, I’ve named this Tag CHTML – Facebook – Base Pixel.

Name new GTM Tag CHTML - Facebook - Base Pixel

Since there isn’t an official integration for Facebook Pixel Tags, we’ll be making a custom one using the Custom HTML tag type.

Select the Custom HTML Tag type

Next, go into your Facebook Events Manager account on a separate tab and grab your unique pixel code. (You can find it under Set UpInstall Pixel Manually add pixel code to website.) You can just click on the code box to copy the whole snippet.

Copy the pixel code from the Facebook Pixel by clicking on the code field

Then, paste this pixel code into the HTML field of your new Tag. 

Paste the pixel code from the Facebook Pixel into the HTML field of your new Tag

Since we’ll need this base Tag to fire first to track any other Facebook events, we’ll want it to fire on all pages across our website.

To do this, we’ll scroll down and click anywhere in the Triggering field, then select the All Pages trigger for this Tag.

Select All Pages trigger for Base Facebook Pixel Tag

Finally, click Save. We’re almost done with this step, so let’s test our Tag to make sure it’s working properly.

Testing Your Base Pixel Tag

Click Preview to enter Google Tag Manager’s preview and debug mode.

Enter GTM Preview mode by clicking Preview button on dashboard

While in preview mode, navigate around your website. If everything is implemented correctly so far, your CHTML – Facebook – Base Pixel Tag should fire on each webpage. 

Base Facebook Pixel Tag firing on the website shown in GTM preview console

I also like to use a browser extension called the Facebook Pixel Helper, which shows here that a PageView event has fired. This is the Tag that we just installed, so we know that the Tag is firing properly and will be sent to our Facebook Ads account.

Facebook Pixel Helper browser extension showing that PageView event has fired

Creating Facebook Event that Fires 5 Seconds After Page Load

Now that we have a base Tag that will load our Facebook Pixel library, we can create more customized event Tags to collect better data.

Next, let’s create a custom event for this Facebook Pixel that fires five seconds after the page load. This accomplishes our goal of tracking only users who are interested in our website and excluding users who bounce.

There are two main steps to this process.

First, we’ll need to create a timer trigger that will wait for five seconds before firing our Tag. 

Second, we’ll need to build a new custom HTML Tag that will track a specific Facebook event without bogging down page loads with extra code.

Create GTM Timer Trigger

To create a new custom trigger, click on Triggers inside of Google Tag Manager and click on New.

Create a new trigger in GTM

We want to create a trigger that fires five seconds after the page loads. 

There is a built-in trigger inside Google Tag Manager that can help use accomplished this called the Timer trigger. 

Select the Timer trigger type for your new trigger

The field Interval determines how long the timer will wait after trigger to fire a Tag. To achieve a five-second delay on our Facebook Pixel Tag, enter 5000 milliseconds in the Interval field.

Set the Interval to 5000 milliseconds for your trigger to make a five-second delay to your Tag firing

If no Limit is placed on this trigger, then it will fire a Tag every consecutive interval. In this case, the Tag would fire again every five seconds.

We only want to fire our Tag once per page, so set the Limit to 1.

Set the Limit to 1 for your trigger to make your Tag fire only once per page

Finally, we need to set the conditions for this trigger. This will tell the trigger when it should start its timer.

We want this trigger to fire on all pages, so we’ll set the conditions to Page Path / matches RegEx /  .*. The dot-star ( .* ) in regular expression notation means that any value will be considered, so the timer will begin on any page on this website.

Set the conditions for your trigger to fire on all pages by choosing Page Path matches RegEx .*

Finally, don’t forget to give your trigger an informative name—Timer – 5 Seconds is pretty self-explanatory—and Save it.

Choose a trigger name such as Timer - 5 Seconds and save it

So with these settings,  we have a timer trigger that fires just once after five seconds on all pages. This is perfect for tracking pageviews from users who don’t bounce.

Build Custom HTML Facebook Tags

Now, let’s create a Tag that uses our new trigger and fires a custom Facebook event. 

Go to Tags, then click on New

Let’s give this Tag a name to distinguish it from our base Tag. I’ll call mine CHTML – Facebook – 5 Seconds

Click in the Tag Configuration field, then choose the Custom HTML tag type.

Name your new Tag and choose the Custom HTML tag type

And here we need to type exactly like this: 

<script>
  fbq('trackCustom','5 Seconds');
</script>
CHTML - Facebook - 5 Seconds Tag HTML code from above pasted into Tag HTML field

This snippet is a piece of JavaScript. The trackCustom element allows us to create our own Facebook event that we can name whatever we want. I will use the name 5 Seconds so we can identify it in the Facebook Ads interface.

Next, we’re going to attach our five-second timer trigger to this Tag that we’ve just built. 

Select five second timer trigger for new Tag

So this piece of code fires five seconds after each page load. 

Click Save—now we’re ready to test our new Tag!

Save the new Tag configuration

Testing Your Delayed Pixel Tag

We’re almost done with this Tag. Our last step is to test it in the Google Tag Manager preview and debug mode.

Enter preview mode on your website. Your base Facebook Pixel Tag should still fire right away when the page loads. Then, after five seconds, you should also see your five-second timer event Tag. This should occur on any page across your website.

Base Facebook Pixel Tag and Facebook five-second delay Tag firing on the website

If you check the Facebook Pixel Helper, you can also see that the PageView has fired and also our 5 Seconds event.

Facebook Pixel Helper showing that PageView and 5 Seconds Tags fired

Finally, we should also make sure that our Facebook Ads account is receiving the correct data from these Tags.

In your Facebook Events Manager, go to Test events. Under the Receiving activity list, you should see events for both your base Tag (Page view) and for your timer Tag (5 Seconds) on each page you opened while in GTM preview mode.

Receiving activity in the Test events tab showing us that both Page view and 5 Seconds Tags have fired multiple times

If you want to test this more carefully and see results in real time, you can also click Clear Activity, refresh your webpage, and come back here. You should see the list populated with data from first your base Tag, then your timer Tag.

Click Clear Activity to reset data and see new Tags fire in real time when you refresh your webpage

Setting Tag Firing Priority

There’s one more step that we should take to ensure that our implementation is airtight.

We want to make sure that our base Tag always fires before the timer Tag, no matter what else happens on the page load. This is because without Facebook library initiating from the base Tag, the timer Tag will not successfully send information to our Facebook Ads account.

In Google Tag Manager, click on your base Facebook Pixel Tag.

Selecting CHTML - Facebook - Base Pixel Tag from list of Tags in Google Tag Manager

To make sure that our base Tag finishes loading the JavaScript library for Facebook before the timer Tag fires, we’ll be using some advanced settings that instruct Google Tag Manager to fire Tags in a certain order.

Code line 11 in the HTML of Facebook Base Pixel Tag begins with fbq(‘init’, which initiates the Facebook Pixel

Under Advanced Settings, find the field labeled Tag firing priority. The higher a Tag’s firing priority compared to other Tags, the earlier it will fire (the default is zero). Any value greater than zero will ensure that this Tag fires before our other Tags.

Then, find the dropdown options under Tag firing options. Here, we want to select Once per event. Finally, click Save.

Tag Advanced Settings, setting Tag firing priority to 10, Tag firing options set to Once per event, and saving the Tag

Creating Facebook Audience in Facebook Pixel Interface

Finally, we can create an audience made up of users tracked by our timer Tag for remarketing purposes. These users are some of the best leads for targeted remarketing since we already know that they’re interested in our website.

In your  Facebook Events Manager, click Create Audience.

Create an audience in your Facebook Pixel by clicking Create Audience

Choose the Facebook Ads account where you’d like to create an audience.

Choose the Facebook Ads account where you’d like to create a custom audience

Choose the correct pixel that is tracking your new events. 

Choose the correct pixel that is tracking your new events for your custom audience

Then, we can create an audience of people who have stayed for at least five seconds by selecting for users tracked by our 5 Seconds event.

Create an audience of people who have stayed at least five seconds by selecting the 5 Seconds delayed pixel event

We also need to determine how long users stay in this audience after being tracked by this event. Remarketing works well within a short timeframe, so I’ll set this to one week.

Create a custom audience of users who stayed for longer than five seconds in the past week by selecting for 5 Seconds delayed pixel events that fired in the past 7 days

Finally, give the audience a name and click Create Audience.

Set audience name such as 5 Seconds and click Create Audience

With this custom audience, you can target users who were interested in your website with your remarketing campaigns.

Summary

So there you have it. This is how you can delay your Facebook pixel to build a higher quality audience.

Check out our guide on Facebook Pixel Purchase & Conversion Tracking with GTM which also improves your ability to track more qualitative data.

Have you already tried delaying your Facebook Pixel firing with Google Tag Manager? How do you optimize your remarketing audiences? Let us know in the comments below!

JOIN US!

Master Data & Analytics with Measuremasters

Exclusive Courses & Workshops | Ongoing Troubleshooting | Support Resources, Tools & much more
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Daniel
Daniel
13 days ago

It would not affect your load time pagespeed?

Blog Categories

Join 30,000+ marketers getting exclusive resources and our latest content!

now it's time to

Start measuring like a master

Itching to jump into the world of MeasureMasters? This is what you have to look forward to.