Facebook Pixel via GTM using GA4 Data Layer Schema | Ahsan Taz
Facebook Pixel Setup via GTM using GA4 Data Layer Schema
!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');
fbq('track', 'PageView');
src=”https://www.facebook.com/tr?id=2931116163786365&ev=PageView&noscript=1″
/>
- View Content Event:
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'
});
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
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'
});
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
- 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:
fbq('track', 'Purchase', {
value: {{dlv - FB - Purchase value}},
currency: 'BDT',
content_type: 'product',
content_ids: {{jsv - FB - Purchase Product - AR}},
});
Source: Combine GTM Product IDs for Facebook Conversion Tags on Magento | Elevar (getelevar.com)
Write a Comment