Facebook Pixel

The Facebook Pixel custom tag template is an unofficial tag template for Google Tag Manager's customs template gallery.

Resource
Vendor documentation
Weblog post
Gallery entry
GitHub repo

Facebook Pixel permissions

Description

This template implements the Facebook Pixel on the website. You lot can use information technology to load the SDK, initiate the pixel(southward), and to send custom and standard events to Facebook with whatsoever custom properties and user attributes y'all wish. The template should be equipped to handle all the functionality of the pixel. Please permit me know in the comments if in that location are features that y'all think are missing!

Instructions

Here are the features of the pixel, together with some detail on how they work.

In general, when the tag fires, it goes through all the Pixel IDs added to the tag. For each one, it offset checks if the pixel has been initialized for the ID. If it hasn't, it proceeds to initialize it (forth with whatever parameters that can be fix with the initialization call). So, the tag proceeds to exercise whatever you've configured it to practice. Information technology volition ship an event with any backdrop y'all have configured, and you can as well utilize the tag to disable things like automatic history upshot tracking.

Annotation! The pixel DOES Non automatically send the PageView tracking hitting like to how the Facebook Pixel snippet does. Y'all will need to create a PageView tag to ship the page view to Facebook.

Facebook Pixel ID(s)

The first field requires y'all to add your Facebook Pixel ID. Y'all can add more than i ID past separating each with a comma, e.chiliad. 123456789,234567890.

If you add together more than one ID, then the tag will initialize (if necessary) and send the hit to all the pixel IDs listed in the field.

Enhanced Ecommerce dataLayer integration

If y'all bank check this push button, then the tag will look in dataLayer for the well-nigh recent object with the ecommerce cardinal. If this object has ane of the following backdrop: detail, add, checkout, or purchase, the tag volition automatically derive the post-obit data from the object to be sent with the tag.

If the dataLayer does not take an ecommerce object, or if the ecommerce object doesn't have 1 of particular, add together, checkout, purchase, or if the ecommerce object doesn't have a products assortment, the tag will cease with a failure.

Event Proper noun is mapped like this:

  • An ecommerce.detail object sets event name as ViewContent.

  • An ecommerce.add together object sets upshot name every bit AddToCart.

  • An ecommerce.checkout object sets consequence name as InitiateCheckout.

  • An ecommerce.purchase object sets event name as Purchase.

Object Properties are mapped like this:

  • A contents parameter is created from the products array, and it is populated with the id and quantity of each product in the latter.

  • content_type is prepare to production.

  • currency is derived from ecommerce.currencyCode, or set to USD by default.

  • num_items is used in InitiateCheckout and Buy and is aggregated from the total quantity of all products in the products array.

  • value is calculated by multiplying the price and quantity of each product in the products array, and summing everything up.

Here's an instance of how an Enhanced Ecommerce object gets mapped into Facebook object properties:

            {   ecommerce: {     currencyCode:              'EUR',     checkout: {       actionField: {         step:              1              },       products: [{         id:              'firstProduct',         name:              'firstProductName',         cost:              '3.15',         quantity:              2,         category:              'prods'              },{         id:              'secondProduct',         name:              'secondProductName',         price:              'vii.35',         quantity:              iii,         category:              'prods'              }]     }   } }              // BECOMES                                          {   content_type:              'production',   currency:              'EUR',   num_items:              5,   contents: [{"id":"firstProduct","quantity":two},{"id":"secondProduct","quantity":3}],   value:              28.35              }                      

Note! Yous can use the Object Properties settings (see beneath) to override these individual properties, if you are unhappy with how some parts of the automatic integration piece of work.

Event Name

If you haven't selected the Enhanced Ecommerce integration, y'all can choose an event proper noun from the list of standard events. You can also specify a custom effect name, or you can use a Google Tag Manager variable to provide the result name dynamically.

If this field gets the value false (nigh usually through a Google Tag Manager variable), the pixel will download the SDK, but information technology will not initialize nor send whatever hits to Facebook.

Enable Advanced Matching

If you check this box, then a new group chosen Client Data Data Parameters appears.

Data Processing Options

Yous tin can add supported data processing options to this field. They are evaluated on a tag-by-tag basis, and are set for all pixel IDs of any given tag.

Customer Data Data Parameters

You can use this to prepare pre-defined parameters for Facebook'due south Avant-garde Matching feature.

Object Properties

Yous have 3 options for adding object properties to the hit.

If you checked the Enhanced Ecommerce integration, some properties will be automatically populated.

Y'all tin also load a properties object using a Google Tag Managing director variable that returns an object with key-value pairs that will and then be added to the hit.

Finally, you can add backdrop manually using the table in the tag. Each row represents one property.

You lot can add pre-defined properties and custom backdrop. Read this for more than information.

Annotation! If you define backdrop using multiple sources (e.chiliad. Enhanced Ecommerce integration AND variable AND the table), and so conflicts are resolved in the order of tabular array > variable > Enhanced Ecommerce. In other words, if you ready content_type in the table, it will override content_type set in a variable or the Enhanced Ecommerce integration.

More Settings

You can check the Disable Automatic Configuration to prevent the pixel from automatically listening to clicks or collecting page metadata.

You lot can check the Disable History Event Tracking to prevent the pixel from automatically tracking pushState and replaceState history events.

You tin can add together an Event ID to deduplicate hits sent from the website and via server-side tracking.

Release notes

Date Changeset
11 November 2020 Added Event ID to pixel fields for server-side deduplication.
23 July 2020 Fix to prevent template save if Advanced Matching list enabled but empty.
vi July 2020 Remove deprecated User Properties. Add Data Processing Options. Set up bug with empty Advanced Matching List.
23 April 2020 Add unit of measurement tests. Add together Enhanced Ecommerce integration.
16 April 2020 Add selection to disable automated tracking of history events.
1 Apr 2020 Fix "country" in Advanced Matching to use correct cardinal.
xix Oct 2019 Fix object belongings bug.
17 October 2019 Fix object merging. Update issue name option to permit using a variable.
12 September 2019 Initial release.