WooCommerce Facebook Pixel: Track Purchase Event using DataLayer & Google Tag Manager
by ShahzadaAliHassan - 8th June 2024By the end of this tutorial, you will be able to track purchase events on your WooCommerce store using Google Tag Manager, Data Layer, and Facebook Pixel. This will help you accurately track Facebook ads conversions, ensuring you capture all conversion events.
Hey guys, welcome back to another guide! If you're new here, my name is H, and I have helped more than 1,000 websites and 25 different agencies configure Google Tag Manager, Google Analytics, Facebook Pixel, and all other tracking tools. In this guide, I’ll show you how to configure Facebook Pixel and track purchase events on a WooCommerce store using Google Tag Manager and the Data Layer.
This tutorial is intended for:
- Business owners configuring Facebook Pixel on their WooCommerce store themselves.
- Agencies setting up tracking for their clients.
- Freelancers looking to upgrade their skills to better track conversions for clients.
This is not a coding-intensive tutorial, so I won’t be diving into PHP or theme templates. Also, this isn’t a general WooCommerce training session, so I won’t cover how coupons or product templates work. Instead, I’ll show you how to create a data layer inside your WooCommerce store using plugins to make your life easier.
I’ve divided this guide into four sections:
- Configuring Google Tag Manager
- Configuring Facebook Pixel
- Enabling the Data Layer
- Creating Tags, Variables, and Tracking Purchase Events
So, without further ado, let’s dive into it!
Section 1: Configuring Google Tag Manager
Step 1: Install the Plugin
- Go to your WooCommerce store’s backend.
- Navigate to the Plugins section and click on Add New.
- Search for the plugin GTM4WP (Google Tag Manager for WordPress) by Thomas Geiger.
- Click Install Now and then Activate.
Step 2: Configure Google Tag Manager
- Once the plugin is activated, go to the Dashboard.
- You will see a message prompting you to enter the GTM ID. Click on it or go to Settings and then Google Tag Manager.
- Enter your GTM Container ID. If you don’t have it, go to your Google Tag Manager account, create a container, and copy the ID.
- Paste the ID into the plugin settings and save changes. Make sure the container code is active by clicking save changes again if needed.
Step 3: Verify the Configuration
- Go to Google Tag Manager and click Preview to open a temporary debug window.
- Navigate to your website, ensuring the debug window is connected.
- Verify that Google Tag Manager is firing correctly by checking the green status in the Tag Assistant extension or the debug window’s connection status.
Section 2: Configuring Facebook Pixel
Step 1: Get Your Facebook Pixel ID
- Go to Facebook Business.
- Click on All Tools and then Event Manager.
- Find or create a pixel under Data Sources. Copy the Pixel ID.
Step 2: Add Facebook Pixel Configuration Tag
- Go to Google Tag Manager, navigate to Templates, and search for the Facebook Pixel template created by the Facebook team.
- Add the template and create a new tag.
- Select the Facebook Pixel tag template, paste the Pixel ID, and configure the tag to fire on all pages.
- Save the tag with a name like Facebook Configuration Tag.
Step 3: Verify Facebook Pixel Configuration
- Click Preview in Google Tag Manager to open the debug window again.
- Go to your website, ensuring the Facebook Pixel fires correctly by using the Facebook Pixel Helper extension.
- Confirm the page view event is firing correctly in the Facebook Event Manager under the test section.
Section 3: Enabling the Data Layer
Step 1: Enable Data Layer in WooCommerce
- Go to the Settings of the GTM4WP plugin in your WooCommerce backend.
- Navigate to the Integration section and find the WooCommerce settings.
- Check the box to Track enhanced e-commerce events.
- Save changes and verify everything is working correctly by making a test purchase.
Step 2: Verify Data Layer Events
- Go to the Cart page and proceed to Checkout.
- Complete a test purchase to see the data layer events.
- Check the Google Tag Manager debug window for the purchase event, ensuring it contains all necessary details like currency, transaction ID, total value, and items purchased.
Section 4: Creating Tags, Variables, and Tracking Purchase Events
Step 1: Create Data Layer Variables
- Go to Google Tag Manager and navigate to Variables.
- Create new Data Layer Variables for each required field:
- Currency:
ecommerce.currency
- Transaction ID:
ecommerce.transactionId
- Affiliation:
ecommerce.affiliation
- Value:
ecommerce.value
- Shipping:
ecommerce.shipping
- Coupon:
ecommerce.coupon
- Items:
ecommerce.items
- Currency:
Step 2: Generate Facebook Parameter Variables
- Go to Templates and search for the Facebook Parameter Generator by STAPE team.
- Create new variables for:
contents
content_ids
content_name
num_items
Step 3: Create the Facebook Pixel Purchase Tag
- Go to Tags and create a new tag using the Facebook Pixel template.
- Set the tag to fire on the custom event purchase.
- Add parameters to the tag using the data layer variables created:
value
:ecommerce.value
currency
:ecommerce.currency
order_id
:ecommerce.transactionId
contents
:Facebook Parameter Generator - contents
content_ids
:Facebook Parameter Generator - content_ids
content_type
:product
content_name
:Facebook Parameter Generator - content_name
num_items
:Facebook Parameter Generator - num_items
tax
:ecommerce.tax
shipping
:ecommerce.shipping
affiliation
:ecommerce.affiliation
coupon
:ecommerce.coupon
Step 4: Verify and Publish
- Click Preview in Google Tag Manager to connect the debug window.
- Complete a test purchase on your website to ensure the purchase event fires correctly.
- Verify the purchase event details in the Facebook Pixel Helper and Facebook Event Manager test section.
- If everything is correct, click Submit in Google Tag Manager to publish the changes.
Bonus section
If you prefer not to manually configure everything, you can download the pre-configured container JSON file provided in the video description and import it into your Google Tag Manager workspace.
Import the Container:
- Go to Admin > Import Container.
- Select the JSON file.
- Choose to merge or overwrite the existing container.
Conclusion
Congratulations! You’ve successfully configured your WooCommerce store to track purchase events using Google Tag Manager, Data Layer, and Facebook Pixel. This setup will help you track all Facebook ads conversions properly and ensure you capture all conversion events accurately.
If you found this guide helpful, check out our other tutorials for more tracking and analytics tips!