How to set up Facebook Pixel using Google Tag Manager

Author:

Setting up Facebook Pixel using Google Tag Manager (GTM) allows you to track events and actions on your website and send this data to Facebook for targeted advertising and analytics purposes. Here’s a step-by-step guide on how to set up Facebook Pixel with GTM:

Prerequisites

Before starting, make sure you have:

  1. Facebook Business Manager account set up.
  2. Facebook Pixel created in your Facebook Business Manager.
  3. Google Tag Manager account and container installed on your website.
  4. Access to edit and publish changes to your website’s GTM container.

Step-by-Step Guide to Set Up Facebook Pixel with Google Tag Manager

Step 1: Find Your Facebook Pixel ID

  1. Log in to Facebook Business Manager:
    • Go to your Facebook Business Manager account.
  2. Navigate to Facebook Pixel:
    • Click on Business Settings.
    • Under Data Sources, select Pixels.
    • Find your existing Facebook Pixel or create a new one if needed.
    • Copy your Pixel ID.

Step 2: Set Up Variables in Google Tag Manager

  1. Log in to Google Tag Manager:
    • Open your GTM workspace.
  2. Create Variables:
    • Go to Variables and click New.
    • Name the variable something like “Facebook Pixel – Pixel ID”.
    • Choose Variable Type as Constant.
    • Enter your Facebook Pixel ID obtained in Step 1.
    • Save the variable.

Step 3: Create a Facebook Pixel Tag in Google Tag Manager

  1. Create a New Tag:
    • Go to Tags and click New.
    • Name the tag something like “Facebook Pixel – Base Code”.
    • Click Tag Configuration and select Custom HTML.
    • Paste the Facebook Pixel base code (JavaScript code) provided by Facebook into the HTML text area. It should look like this:
      html
      <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', '{{Facebook Pixel ID}}');
      fbq('track', 'PageView');
      </script>
      <noscript><img height="1" width="1" style="display:none"
      src="https://www.facebook.com/tr?id={{Facebook Pixel ID}}&ev=PageView&noscript=1"
      />
      </noscript>
    • Replace {{Facebook Pixel ID}} with the GTM variable you created in Step 2 ({{Facebook Pixel - Pixel ID}}).
    • Save the tag.

Step 4: Set Trigger for Facebook Pixel Tag

  1. Create a Trigger:
    • Go to Triggers and click New.
    • Name the trigger something like “All Pages – Page View”.
    • Choose Trigger Type as Page View.
    • Configure the trigger to fire on all pages (Page View > Some Page Views > Page URL > matches RegEx > .*).
    • Save the trigger.

Step 5: Test and Publish

  1. Test Your Setup:
    • Click Preview in GTM to enter preview mode.
    • Navigate to your website and ensure the Facebook Pixel base code fires correctly (you can check in the browser console for pixel events).
  2. Publish Your Container:
    • Once testing is successful, click Submit in GTM to publish your container changes.

Step 6: Verify in Facebook Events Manager

  1. Check Events in Facebook Events Manager:
    • Go back to your Facebook Business Manager.
    • Navigate to Events Manager.
    • Check that your Pixel is receiving data (you should see PageView events).

Additional Configurations

  • Custom Events: Modify the Facebook Pixel base code in GTM to track custom events such as purchases, sign-ups, or other actions users take on your website.
  • Dynamic Remarketing: Set up additional tags in GTM to implement dynamic remarketing with Facebook Pixel, using variables to pass dynamic values like product IDs and prices.

By following these steps, you can effectively set up Facebook Pixel using Google Tag Manager. This integration allows you to track user interactions on your website and optimize your Facebook advertising campaigns based on real user behavior data.