For many companies, social traffic is very important. And there is one behemoth in the playground; Facebook. There are some great ways to use a Facebook Pixel in order to start measure conversions and optimize adverts you’re running on the platform. Not only that, the pixel allows you to create audiences for remarketing as well. That opens up for a really good targeting on Facebook for your audiences.
In order to start using the pixel you’ll have to create it using the Ads Manager.
Just start by creating a pixel and giving a unique name. Note that you’re only allowed to have one Facebook Pixel per account, so choose a name that best represents your business.
Once you’ve selected your name, hit the Install Pixel Now button, and you’ll see the actual code you need to add to your pages.
<!-- 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', 'XXXXXXXXXXXXXXXX'); fbq('track', 'PageView'); </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=XXXXXXXXXXXXXXXX&ev=PageView&noscript=1" /></noscript> <!-- DO NOT MODIFY --> <!-- End Facebook Pixel Code -->
Note: You are going to need your id variable in the code (highlighted above) to be your own, so don’t copy/paste this code. Use the one you received in Facebook Ads Manager.
Head into your account in Google Tag Manager and create a new tag.
Tags -> Tag Configuration
Paste your code into the HTML Textarea above and make sure that you select All Pages under Triggering in order to have the tag fire on every page on your site.
Preview your changes in Google Tag Manager and make sure that the script fires as intended.
With that in place you’re now good to go and can publish your changes in Google Tag Manager. This will not make sure that you start tracking your users through the Facebook Pixel as well which will open up more possibilities in Facebook when it comes to following up what your users are doing (or not doing) on your site.
Add Facebook Conversion Tracking
Chances are that you don’t want to track only pages shown, but you probably want to add some Facebook conversion tracking as well. Facebook comes with some easy ways to follow up on conversion on your site as well. These include but are not limited to the following.
View Content
fbq('track', 'ViewContent');
Using this code on your content related pages ensures that Facebook will get information when users are visiting pages on your site. The code need to be added on the pages after the pixel code.
If you have a blog or specific product pages you’d like to track in order to see if your users are engaging with them, just add the code above to a Custom HTML tag (inside <script> tags) and make sure that the tag fires after the Facebook Pixel tag.
On this particular site all product related content resides under the section /tjanster/ (services in English) so I’ll configured the Trigger to fire when Page has loaded (making sure that the Facebook Pixel is there). You could use Tag Sequencing instead if you like.
Add To Cart
fbq('track', 'AddToCart');
If you’re running an e-commerce and would like to track when your visitors are adding a product to the cart you would use the code above. Make sure that this code fires in the same sequence as your Google Analytics enhanced e-commerce tracking for AddToCart fires. Just add this line of code to the same function as you’re already using.
Complete Registration
fbq('track', 'CompleteRegistration');
If your intent is to have your visitors signing up for a service or subscription you will have to make use of the CompleteRegistration event code as stated above. Same goes as with the Add To Cart code; make sure to fire this line of code when the user has been registered or the form has been submitted.
Other Facebook Event Codes
There are numerous other event codes to be used, please see the Facebook official documentation. Just make sure to add them on your page when the event has actually happened. Do not add them when the page loads (except e.g. View Content) since that will skew your data.
Thanks so much for this great explanation! I would definitly test this out.
Thanks men :)
Hey,
Your guide says to “make sure that the tag fires after the Facebook Pixel tag.” but the official documentation says to fire the base code after the event tag: https://www.facebook.com/business/help/952192354843755?helpref=faq_content#addeventcode
So which is it?
@Aaron
The official documentation says “Keep in mind the base code must fire before the standard event.”
And it must be that way. The “base code” defines the fbq object and loads the fbevents.js javascript. Without that loaded, any “track” method would fail.
FWIW, using tag sequencing in GTM is the best way to guarantee that the base code has loaded before any additional FB Events are sent.
Thanks for letting me know about adding facebook pixel gtm