DataLayer for Google Tag Manager
How To Configure
Purchase Extension

Related Extensions

Get more from your Magento2 store!

Catalog Hover Image for Magento

Quickly previewing alternative product images on your category list page.

DataLayer for Tag Manager

Whether you are integrating Bing, Facebook, SnapChat, Pinterest, or any other services our extension make it easy.

Enhanced Success Page

Add cross-sell, upsell, related products, social media links and other elements to your order confirmation.

Integrate Facebook Tracking Pixel with Google Tag Manager

Product Page View
Tag Configuration
  Tag type : Custom Html

Trigger Configuration
  Trigger: All Custom Events
  Event Name : productPage

HTML

<script>
require(['DataLayerProductApi'], function (dataLayerProductApi) {
    var product = dataLayerProductApi();
    
    <!-- Facebook Pixel Code -->
    fbq('track', 'ViewContent', {
        content_name: product.getProduct('name'),
        content_category: product.getProduct('path'),
        content_ids: product.getProductSkus(),
        content_type: 'product',
        value: product.getProduct('price'),
        currency: product.getCurrencyCode()
    });
    <!-- End Facebook Pixel Code -->
});
</script>
Add To Cart
Tag Configuration
  Tag type : Custom Html

Trigger Configuration
  Trigger: All Custom Events
  Event Name : addToCart

HTML

<script>
require(['DataLayerProductApi'], function (dataLayerProductApi) {
    var product = dataLayerProductApi();
    
    var fbFieldFormat = {
        renameFieldTo: {id:'id', quantity:'quantity', price:'item_price'},
        appendIndex: false
    };
    
    <!-- Facebook Pixel Code -->    
	fbq('track', 'AddToCart', {
        content_category: product.getProduct('path'),
        contents: product.getAddedToCartItems(fbFieldFormat),
        content_type: 'product',
        currency: product.getCurrencyCode()
    });
    <!-- End Facebook Pixel Code -->
});
</script>
Initiate Checkout
Tag Configuration
  Tag type : Custom Html

Trigger Configuration
  Trigger: All Custom Events
  Event Name : checkoutPage

HTML

<script>
require(['DataLayerCheckoutApi'], function (dataLayerCheckoutApi) {
    var checkout = dataLayerCheckoutApi();
     
    var fbFieldFormat = {
        renameFieldTo: {id:'id', quantity:'quantity', price:'item_price'},
        appendIndex: false
    };
    
    <!-- Facebook Pixel Code -->
	fbq('track', 'InitiateCheckout', {
        contents: checkout.getItems(fbFieldFormat),
        content_type: 'product',
        currency: checkout.getCurrencyCode(),
        value: checkout.getCart('total'),
        num_items: checkout.getCart('cartQty')
    });
    <!-- End Facebook Pixel Code -->
});
</script>
Purchase
Tag Configuration
  Tag type : Custom Html

Trigger Configuration
  Trigger: All Custom Events
  Event Name : purchase

HTML

<script>
require(['DataLayerPurchaseApi'], function (dataLayerPurchaseApi) {
    var purchase = dataLayerPurchaseApi();
    
    var fbFieldFormat = {
        renameFieldTo: {id:'id', quantity:'quantity', price:'item_price'}
    };
    
    <!-- Facebook Pixel Code -->
	fbq('track', 'Purchase', {
        contents: purchase.getItems(fbFieldFormat),
        content_type: 'product',
        currency: purchase.getCurrencyCode(),
        value: purchase.getOrder('total'),
        num_ids: purchase.getItemCount()
    });
    <!-- End Facebook Pixel Code -->
});
</script>
Related

Related Extensions

Get more from your Magento2 store!

Enhanced Transactional Emails

Get more from your order confirmation emails by promoting other complementary products.

Catalog Hover Image for Magento

Quickly previewing alternative product images on your category list page.

DataLayer for Tag Manager

Whether you are integrating Bing, Facebook, SnapChat, Pinterest, or any other services our extension make it easy.