Mata Pixel
Using Mata Pixel, we can send tracking data to Facebook. There are two ways to send tracking data.
- Javascript
- Conversion API
Javascript method
You need pixel id and event name. The below is sample code to send a PageView event
<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>
There are two options to send event using Javascript
- Emebed the above code snippet in the webpage
- Run that code snippet directly. For example, for React page, we can run this Javascript code snippet directly using react hook useDidMountEffect
Test web browser events using the test events tool
- Log into Facebook business account
- Go to Events Manager
- Click the Data sources icon on the middle side of the page
- Click Test events
- Find the browser events section
- If do not see the browser events section, click clear event
- Enter your website URL and click Open website. This opens your website in a separate window or tab
- Do what you normally do to this website. Event will be recorded
- Go back to Test Event section to check events recorded
Deduplication
If we send the same event using both conversion API and embedded javascript, Meta can use event id to deduplication. Meta will treat event with the same event id as the same event.
//use JS to send out event id
fbq('track', 'Purchase', {value: 12, currency: 'USD'}, {eventID: 'EVENT_ID'});
fbq('track', 'Lead', {}, {eventID: 'EVENT_ID'});
Specifications for Meta Pixel standard events
Developer Guide for Mata Pixel