Implement Facebook Pixel in ConvertPlus and Inline carts through Google Tag Manager
A. Create a tag for Facebook Pixel Page View Initialization
1
2
3
<!-- 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', '{your-pixel-id-goes-here}');
fbq('track', 'PageView');
</script>4

B. Create a User-defined variable in Google Tag manager called “ecommerce”
1

2
3
4

C. Create a User-defined variable in Google Tag Manager for Facebook called ConvertPlus - FacebookEventsScript
1

2
3
4
function(){
var attr = {};
attr.currency = "USD";
attr.content_type = "product";
var fbContents,fbIds,fbNames,i;
//function fbData
var fbData = function() {
fbContents = [];
fbIds = [];
fbNames = [];
attr.num_items = {{ecommerce}}.items.length;
for(i=0;i<{{ecommerce}}.items.length;i++){
fbContents.push({
'id':{{ecommerce}}.items[i].item_id,
'name':{{ecommerce}}.items[i].item_name,
'quantity':{{ecommerce}}.items[i].quantity
});
fbIds.push({{ecommerce}}.items[i].item_id);
fbNames.push({{ecommerce}}.items[i].item_name);
}
attr.contents = fbContents;
attr.content_ids = fbIds;
attr.content_name = fbNames;
};
if({{Event}} === 'begin_checkout'){
attr.value = {{ecommerce}}.actionField.checkout_valueUSD;
fbData();
}
if({{Event}} === 'purchase'){
attr.value = {{ecommerce}}.actionField.valueUSD;
fbData();
}
return attr;
}D. Create a trigger specifically for the purchase event
1
2
3

E. Create a tag for the Facebook Pixel for the purchase event
1
2
3
4
<script>
fbq('track', 'Purchase', {{ConvertPlus - FacebookEventsScript}},{eventID:
{{ecommerce}}.transaction_id});
</script>5

Optional – send information with the Facebook Pixel at checkout if needed
Create a trigger specifically for the checkout event
1
2
3

Create a tag for the Facebook Pixel for the checkout event
1
2
3
4
5

PreviousAdobe Analytics with DatastreamsNextImplement Facebook Pixel in Default Carts through Google Tag Manager
Last updated
Was this helpful?