Facebook Pixel via GTM using GA4 Data Layer Schema | Ahsan Taz

<!– Facebook 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’, ‘235339781558921’);

</script>

<!– End Facebook Pixel Code –>

<script>

  fbq(‘track’, ‘PageView’);

</script>

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

src=”https://www.facebook.com/tr?id=2931116163786365&ev=PageView&noscript=1″

/></noscript>

  • View Content 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>

Create Data Layer Variables (Name – Data Layer Variable Name) :

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

Trigger:

Event equals: view_item

  • 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>

Create Data Layer Variables (Name – Data Layer Variable Name) :

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

Trigger:

Event equals: add_to_cart

  1. Purchase Event:

Step – 01: Create Data layer variable for pushing Purchase value

Name – Data Layer Variable Name: dlv – FB – Purchase value
ecommerce.purchase.actionField.revenue
or 

ecommerce.value

Step – 02: Create Data Layer Variable for Products (Multiple items)

Name – Data Layer Variable Name: dlv – FB – Purchase Product  ecommerce.items 

Step – 03: Create Custom JavaScript Variable to push multiple products info from Array 

Name: jsv – FB – Purchase Product – AR

Code: 

function() {

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

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

}

Step – 04: Create Trigger for purchase event

Event equals: purchase

Step -05: Create tag and finally test from preview mode

Code: 

<script>

    fbq(‘track’, ‘Purchase’, {

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

    currency: ‘BDT’,

    content_type: ‘product’,

    content_ids: {{jsv – FB – Purchase Product – AR}},

    });

</script>

Source: Combine GTM Product IDs for Facebook Conversion Tags on Magento | Elevar (getelevar.com) 

Still, facing difficulties?


Hire Me

Write a Comment

Your email address will not be published. Required fields are marked *