Skip to main content

Track Pageviews and Purchases in Meta Pixel

Quickstart Templates Available

We offer pre-configured Google Tag Manager templates that can help you quickly set up Meta Pixel tracking, whether for your entire venue or for specific promoter events. Check out our Analytics Quickstart guide to choose the right template for you.

The following steps take place in Google Tag Manager and will result in installing a Meta Pixel on Spektrix iframes. Unless otherwise stated, naming conventions of Tags, Triggers, and Variables are up to you; however, for the sake of troubleshooting, we recommend to initially use our suggestions.

Add the Pixel Template

The implementation of Meta Pixel requires the addition of a Google Tag Manager template to your Google Tag Manager workspace.

  • Go to Templates on the left-hand side of your workspace

GTM Templates

  • Click Search Gallery

  • Find Facebook Pixel by facebookarchive

GTM facebookarchive

  • Click Add to workspace

Create Configuration Variables

Before creating your tags, we recommend creating variables to store your ID and currency settings. If you have already set these variables up previously, please skip them.

  1. Go to Variables > User-Defined Variables > New.
  2. Create a Constant variable named Your Meta Pixel ID.
  3. Enter your Meta Pixel ID as the value.
  4. Click Save.
  5. Create another Constant variable named Spektrix System Currency.
  6. Enter your 3-letter currency code (e.g., GBP, USD) as the value.
  7. Click Save.

Setup Pageview Tracking

Prerequisites
  • A Google Tag Manager account
  • Your GTM container added to the Spektrix iframes (see “Add a GTM Container to Spektrix iframes”)
  • The Facebook Pixel Template added to your Google Tag Manager workspace
  • Your Meta Pixel ID (from your Meta Business account)
Checklist

By the end of the set up you should have:

  • a Pageview Tag
  • a Data Layer Variable called ecommerce.value
  • a Data Layer Variable called ecommerce.transaction_id
  • a Variable to avoid Duplicate Transactions called customvariable.transactionIsNew
  • a Purchase Trigger
  • a Purchase Tag

In order to track pageviews in Meta's platform, we will setup a Meta Pixel Tag.

  1. Create a new Tag called Meta Pixel - Pageviews.
  2. In Tag Configuration, choose the tag Facebook Pixel which will be found under Custom
  3. Add the variable {{Your Meta Pixel ID}}.
  4. For Event Name, select Standard > PageView.
  5. Under Triggering, select the trigger All Pages
  6. Click Save

A properly setup Meta Pixel Pageview Tag should look like this:

GTM pageviews

Setup Purchase Tracking

The Data Layer provided when a Transaction is confirmed is optimized for use with Google Analytics 4 and not for Meta. In order to make the data compatible with Meta's platform, a more complex Google Tag Manager setup utilizing Variables is required.

Step 1: Create the Order Value and Transaction ID Variables

Order Value

This Variable will pass the Order total to Meta.

  1. On the left-hand side of the Google Tag Manager Workspace, navigate to Variables
  2. Under User-Defined Variables, create a new Variable named ecommerce.value
  3. In Variable Configuration select Data Layer Variable under Page Variables
  4. Set the Data Layer Variable name to be ecommerce.value. This needs to be the exact name of the variable, and is case sensitive.
  5. Click Save

A properly setup Meta Pixel Order Value Variable should look like this:

GTM ecommerce value

Transaction ID

Repeat the same process for the Order ID variable

  1. On the left-hand side of the Google Tag Manager Workspace, navigate to Variables
  2. Under User-Defined Variables, create a new Variable named ecommerce.transaction_id
  3. In Variable Configuration select Data Layer Variable under Page Variables
  4. Set the Data Layer Variable name to be ecommerce.transaction_id. This needs to be the exact name of the variable, and is case sensitive.
  5. Click Save

Step 2: Create the Variable to Prevent Duplicate Transactions

Google Analytics will de-duplicate Order information by default but Meta will not. Setting up this Variable will prevent passing duplicate transactional information to Meta.

Enable Built-in Variable

This solution uses the {{Page Hostname}} variable. Ensure this is enabled in your workspace under Variables > Built-in Variables > Configure.

  1. Under Variables > User-Defined Variables, create a new Variable named customvariable.transactionIsNew
  2. In Variable Configuration, select Custom JavaScript under Page Variables.
  3. Paste in the following code:
function() {
var txnId = {{ecommerce.transaction_id}};
if (!txnId) return false;

var key = 'spektrix_txn_' + {{Page Hostname}};
var localStorageTxnId = localStorage.getItem(key)
if (localStorageTxnId === txnId) {
return false;
} else {
localStorage.setItem(key, txnId);
return true;
}
}
  1. Click Save

Step 3: Create the Purchase Trigger

  1. Create a new Trigger called Spektrix Purchase Trigger for Meta.
  2. Select Custom Event as the Trigger type.
  3. Enter Spektrix Transaction as the event name. This needs to be the exact name of the event, and is case sensitive.
  4. Select Some Custom Events for the trigger to fire on.
  5. Set the conditions for the trigger {{customvariable.transactionIsNew}} equals true
  6. Save.

A properly setup Meta Pixel Purchase Trigger should look like this:

GTM transaction meta

Step 4: Create the Purchase Tag

  1. Create a new Tag Meta Pixel - Purchase
  2. In Tag Configuration, choose tag type ‘Facebook Pixel’ under ‘Custom’.
  3. Add the variable {{Your Meta Pixel ID}}.
  4. For Event Name, select Standard > Purchase.
  5. Expand the Object Properties section, click ‘Add Row’ twice and enter:
Property NameValue
currency{{Spektrix System Currency}}
value{{ecommerce.value}}
  1. Set the trigger to be the custom event Spektrix Purchase Trigger for Meta.
  2. Save

A properly setup Meta Pixel Purchase Tag should look like this:

GTM transaction meta

Setup Purchase Tracking for Specific Items

Prerequisites
  • A Google Tag Manager account
  • Your GTM container added to the Spektrix iframes (see “Add a GTM Container to Spektrix iframes”)
  • The Facebook Pixel Template added to your Google Tag Manager workspace
  • A Meta Pixel ID (from an external Meta Business account)
Checklist

By the end of the set up you should have:

  • a Data Layer Variable ecommerce.value
  • a Data Layer Variable ecommerce.items
  • a Data Layer Variable ecommerce.itemIds
  • an Item Specific Purchase Trigger (for every new item you want to track)
  • an Item Specific Purchase Tag (for every new Meta Pixel provided)

On occasion, you might need to track information on Orders that only contain specific items (and their corresponding information). This tends to be needed if an external company you are working with wants to track the specific items relevant to them. For example, an external producer may want to run Meta adverts for their specific Event and to track conversions from their advert.

The steps below explain what you need to set up in Google Tag Manager so that a Meta Pixel only tracks Transactions that contain Tickets to their Event.

Quick Setup (Recommended)

If you want to avoid manually creating variables and triggers, we have a pre-configured template for this exact scenario.

  1. Go to our Analytics Quickstart.
  2. Follow the instructions in Path 2: Adding a Promoter Pixel to download and import the template.

We will begin by creating three User Defined Variables in your Google Tag Manager workspace. Once the Variables are setup, they can be reused in the future if/when you need to send information to a new external Meta Pixel. If the Variables below already exist from previous work in Google Tag Manager, you can skip to Step 4 to setup the Trigger(s).

Step 1: Create Order and Promoter Variables

Order Value

This Variable will pass the Order total to Meta.

  1. On the left-hand side of the Google Tag Manager Workspace, navigate to Variables
  2. Under User-Defined Variables, create a new Variable named ecommerce.value
  3. In Variable Configuration select Data Layer Variable under Page Variables
  4. Set the Data Layer Variable name to be ecommerce.value. This needs to be the exact name of the variable, and is case sensitive.
  5. Click Save

A properly setup Meta Pixel Order Value Variable should look like this:

GTM ecommerce value

Promoter Pixel ID

  1. Create a Constant Variable named Meta Pixel ID [External/Promoter].
  2. Enter the Promoter's Pixel ID as the value.
  3. Click Save.

Promoter Item ID

  1. Create a Constant Variable named Spektrix Item ID for Meta Pixel [External/Promoter].
  2. Enter the formatted Item ID you wish to track (see below).
  3. Click Save.

Formatting IDs:

  • Event Tickets: T[EventID]I (e.g., T12345I)
  • Merchandise: M[ItemID]- (e.g., M200-)
  • Donations: D[ItemID], (e.g., D7808,)

Finding the ID:

  • Events: Admin Interface > Events > [your event] > Basic Details > Event ID.
  • Other: Use the API Lookup tool.

Step 2: Create the Items Array Variable

This Variable will access the individual items in the Data Layer.

  1. Create a new Variable named ecommerce.items.
  2. In Variable Configuration select Data Layer Variable.
  3. Set the Data Layer Variable name to be ecommerce.items.
  4. Save

A properly setup Meta Pixel Items Array Variable should look like this:

GTM ee items variable

Step 3: Create the Concatenated Item IDs variable

This Variable pulls all the Item IDs from a completed Order, which will allow you to identify the specific items you are looking for.

  1. Create a new Variable named ecommerce.itemIds.
  2. In Variable Configuration select Custom JavaScript.
  3. Paste in the following code:
function() {
var item_idString = {{ecommerce.items}}[0].item_id;
var numItems = {{ecommerce.items}}.length;
for(var i=1; i<numItems; i++) {
var nextItemName = {{ecommerce.items}}[i].item_id;
item_idString = item_idString + ',' + nextItemName;
}
return item_idString;
}
  1. Save

Step 4: Create the Item Check Variable

This variable returns true if the specific item ID is found in the current order.

  1. Create a new Variable named customvariable.itemIdInOrder.
  2. In Variable Configuration select Custom JavaScript.
  3. Paste in the following code:
function() {
var myConstant = {{Spektrix Item ID for Meta Pixel [External/Promoter]}};
var itemIds = {{ecommerce.itemIds}};

// Check if itemIds contains your constant value
if (itemIds && itemIds.indexOf(myConstant) > -1) {
return true;
}
return false;
}
  1. Click Save

Step 5: Create the Promoter Revenue Variable

This variable calculates the total revenue only for items matching the Promoter's ID.

  1. Create a new Variable named customvariable.onlyItemValue.
  2. In Variable Configuration select Custom JavaScript.
  3. Paste in the following code:
function() {
var spxTxnItems = {{ecommerce.items}}
var specItemId = {{Spektrix Item ID for Meta Pixel [External/Promoter]}}
var metaItemSum = 0
var itemsArrayLength = spxTxnItems.length
for (var i = 0; i < itemsArrayLength; i++) {
var iterItem = spxTxnItems[i]
if (iterItem.item_id.includes(specItemId)) {
var specificMetaItemSum = iterItem.price * iterItem.quantity
metaItemSum += specificMetaItemSum
}
}
return metaItemSum
}
  1. Click Save

Step 6: Create an Item Specific Trigger

info

Steps 4 and 5 may be repeated as many times as is required to pass data on different specified items

Set up triggers so that your Purchase Tags only fire when the Transaction contains Tickets for the specific Event.

  1. Identify the specific Item ID in the format required for the Trigger

If you want to track a specific Event, you can find the Event ID in Spektrix by navigating to Admin Interface > Events > [your event] > Basic Details > Event ID:

GTM example of event ID

Alternatively, if you do not have access to the Admin Interface, or would like to track items that are not Event Tickets, use the Spektrix API or the API Lookup tool. When looking the ID up via these methods, they will be much longer than normal: you will only need the numbers from the beginning of the string. For example, if the ID is 50601ARPGPBJPBBJPGRVPTHVCMTBCKDRT you only need 50601.

  1. Using the numeric ID, determine the Trigger Value using the below formats:
Item TypeFormat to Use in TriggerExample Item IDExample Trigger Value
Event TicketT[eventID]IEvent ID = 82811T82811I
MerchandiseM[itemID]-Merchandise ID = 200M200-
DonationD[itemID],Donation ID = 7808D7808,
  1. Create a new Trigger named Spektrix Purchase Trigger for Meta - Specific Item [External/Promoter].
  2. In Trigger Configuration select Custom Event.
  3. Enter Spektrix Transaction as the event name.
  4. Select Some Custom Events.
  5. Set criteria to be customvariable.itemIdInOrder equals true.
  6. Set the second condition to be customvariable.transactionIsNew equals true.
  7. Save

This trigger can then be used to fire a tag when and only when a confirmed Order contains Tickets to the specified Event.

Step 7: Create an Item Specific Purchase Tag

  1. Create a new Tag Meta Pixel - Specific Item Purchase [External/Promoter].
  2. In Tag Configuration, choose tag type Facebook Pixel.
  3. Add the variable {{Meta Pixel ID [External/Promoter]}}.
  4. For Event Name, select Standard > Purchase.
  5. Expand Object Properties, click Add Row twice and enter:
Property NameValue
currency{{Spektrix System Currency}}
value{{customvariable.onlyItemValue}}
  1. Set the trigger to be Spektrix Purchase Trigger for Meta - Specific Item [External/Promoter].
  2. Save

A properly set up Meta Pixel Item Specific Purchage Tag should look like:

GTM meta pixel purchase item tag