Setup Facebook Pixel via Google Tag Manager


 

Facebook pixel Community Template Gallery



  1. Base Code with PageView Event 


<!-- Meta Pixel Code -->

<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', '1795805000795623');

  fbq('track', 'PageView');

</script>

<noscript><img height="1" width="1" style="display:none"

  src="https://www.facebook.com/tr?id=1795805000795623&ev=PageView&noscript=1"

/></noscript>

<!-- End Meta Pixel Code -->




Tag

Use Facebook Tag Template for PageView Event 

Trigger

All Pages 

Variable

  1. event_id




















  1. ViewContent Event: 


<script>

    fbq('track','ViewContent',{

    content_type: 'product',

    content_ids: {{dlv - fb - product id}},

    content_name: {{dlv – fb - product name}},

    value: {{dlv – fb - product price}},

    currency: 'BDT'

    });

</script>



Tag

Use Facebook Tag Template for ViewContent Event

Trigger

Event equals: view_item

Variable & Parameters 

  1. content_type - ( product or product_group )

  2. content_name -{{dlv – fb - product name}}

  3. content_ids -{{dlv – fb - product id}}

  4. value -{{dlv – fb - product price}}

  5. currency -{{dlv – fb - currency}}

  6. event_id



Data Layer Variables (Name - Data Layer Variable):


dlv - fb - product id : ecommerce.items.0.item_id

dlv – fb - product price : ecommerce.items.0.price

dlv – fb - product name : ecommerce.items.0.item_name

dlv – fb - currency : ecommerce.currency













  1. Add to cart Event


<script>

    fbq('track','AddToCart',{

    content_type: 'product',

    content_ids: {{dlv - fb - product id}},

    content_name: {{dlv – fb - product name}},

    value: {{dlv – fb - product price}},

    currency: 'BDT'

    });

</script>




Tag

Use Facebook Tag Template for AddToCart Event

Trigger

Event equals: add_to_cart

Variable & Parameters 

  1. content_type - ( product or product_group )

  2. content_name -{{dlv – fb - product name}}

  3. content_ids -{{dlv – fb - product id}}

  4. value -{{dlv – fb - product price}}

  5. currency -{{dlv – fb - product currency}}

  6. event_id



Data Layer Variables (Name - Data Layer Variable):


dlv - fb - product id : ecommerce.items.0.item_id

dlv – fb - product price : ecommerce.items.0.price

dlv – fb - product name : ecommerce.items.0.item_name

dlv – fb - currency : ecommerce.currency









  1. Purchase Event: 


<script>

    fbq('track', 'Purchase', {

    value: {{dlv - FB - Purchase value}},

    currency: 'BDT',

    content_type: 'product',

      content_name: {{cJS - FB - Purchase Product Name}},

    content_ids: {{cJS - FB - Purchase Product ID}},

    });

</script>



Tag

Use Facebook Tag Template for Purchase Event

Trigger

Event equals: purchase

Variable & Parameters 

  1. content_type - ( product or product_group )

  2. content_name -{{cJS - FB - Purchase Product Name}}

  3. content_ids -{{cJS - FB - Purchase Product ID}}

  4. value -{{dlv – fb - product price}}

  5. currency -{{dlv – fb - product currency}}

  6. order_id -{{dlv – fb - Order ID}}

  7. event_id



Data Layer Variables (Name - Data Layer Variable):


dlv - FB - Purchase value : ecommerce.value

dlv - FB - Order ID : ecommerce.transaction_id


dlv - FB - Purchase Product : ecommerce.items 











Custom JavaScript Variable to push multiple products info from Array:


Variable Name: cJS - FB - Purchase Product ID

function() {

 var items = {{dlv - FB - Purchase Product}};

 return items.map(function(items) { return items.item_id; }).join();

}


Variable Name: cJS - FB - Purchase Product Name

function() {

 var items = {{dlv - FB - Purchase Product}};

 return items.map(function(items) { return items.item_name; }).join();

}






















  1. InitiateCheckout Event: 


Tag

Use Facebook Tag Template for InitiateCheckout Event

Trigger

Event equals: begin_checkout

Variable & Parameters 

  1. content_type ( product or product_group ) 

  2. content_name -{{cJS - FB - Purchase Product Name}}

  3. content_ids -{{cJS - FB - Purchase Product ID}}

  4. value -{{dlv – fb - product price}}

  5. currency -{{dlv – fb - product currency}}

  6. event_id



Data Layer Variables (Name - Data Layer Variable):


dlv - FB - Purchase value : ecommerce.value


dlv - FB - Purchase Product : ecommerce.items 




Custom JavaScript Variable to push multiple products info from Array:


Variable Name: cJS - FB - Purchase Product ID

function() {

 var items = {{dlv - FB - Purchase Product}};

 return items.map(function(items) { return items.item_id; }).join();

}


Variable Name: cJS - FB - Purchase Product Name

function() {

 var items = {{dlv - FB - Purchase Product}};

 return items.map(function(items) { return items.item_name; }).join();

}








  1. AddToWishlist Event: 


Tag

Use Facebook Tag Template for InitiateCheckout Event

Trigger

Event equals: begin_checkout

Variable & Parameters 

  1. content_type ( product or product_group ) 

  2. content_name -{{cJS - FB - Purchase Product Name}}

  3. content_ids -{{cJS - FB - Purchase Product ID}}

  4. value -{{dlv – fb - product price}}

  5. currency -{{dlv – fb - product currency}}

  6. event_id



Data Layer Variables (Name - Data Layer Variable):


dlv - FB - Purchase value : ecommerce.value


dlv - FB - Purchase Product : ecommerce.items 




Custom JavaScript Variable to push multiple products info from Array:


Variable Name: cJS - FB - Purchase Product ID

function() {

 var items = {{dlv - FB - Purchase Product}};

 return items.map(function(items) { return items.item_id; }).join();

}


Variable Name: cJS - FB - Purchase Product Name

function() {

 var items = {{dlv - FB - Purchase Product}};

 return items.map(function(items) { return items.item_name; }).join();

}













What to do After Setting up Facebook Pixel: 

  1. Connecting Pixel with Ad Account 

  2. Connecting Pixel with Facebook Catalog 

  3. Domain Verification 

  4. Setup Aggregated Event Measurement for iOS 14 update 









Improve Facebook Event Match Quality 








Google Tag Manager custom javascript variable to calculate the total cart value



















Source: 






Page