Facebook Pixel implementation: some references.


Implementation – Facebook Pixel

Cookie consent and GDPR

If you plan to serve European Union you will need to implement GDPR.

General Data Protection Regulation (GDPR) | Facebook for Business

Which means you will need to ask for user consent before tracking their activity on your website that involves personal data. Fortunately Facebook offers an API to pause Pixel from firing and fires once consent is granted:

fbq('consent', 'revoke');
fbq('consent', 'grant');

General Data Protection Regulation – Facebook Pixel

You can also use a tag manager for that purpose.

Tracking Events

Facebook Pixel API offers a wide range of standard events to track.


fbq('track', 'Purchase', {currency: "USD", value: 30.00});
fbq('track', 'AddToCart', {currency: "USD", value: 30.00});
fbq('track', 'PageView');

You will find the complete list of standard event here Reference – Facebook Pixel.

Custom Events

fbq('trackCustom', 'ShareDiscount', {promotion: 'share_discount_10%'});

Conversion Tracking – Facebook Pixel

Parameters and Object properties

In the examples above you may have notice that some code got additional information beside the event name.

{currency: "USD", value: 30.00}
{promotion: 'share_discount_10%'}

Those are optional parameters written as JSON-formatted objects and allow to include additional information to your events.

We have seen value parameters and promotion but you might want to add the category where the event took place

{content_category: "name_of_category"}

You can just as easily create custom parameters.

{custom_parameters: "some_value"}

or even more complex objects:

{contents: [
        id: '301',
        quantity: 1
        id: '401',
        quantity: 2

You will find more information on the link above where parameters are treated, plus you have some example above.