Aman Kumar

Oct 21, 2020

2 min read

Integrate Facebook Pixel and Fb Pixel Events in GatsbyJs

Gatsby-Plugin-Facebook-Pixel
Facebook Pixel Event in Gatsby

Problem Statement

npm i gatsby-plugin-facebook-pixel
// In your gatsby-config.js 
plugins: [
{
resolve: `gatsby-plugin-facebook-pixel`,
options: {
pixelId: "pixel id here",
},
}
];

Adding facebook pixel events

Facebook event tracking

fbq('track', 'Purchase', {currency: "USD", value: 30.00});
fqb is not defined
if (typeof window !== "undefined") {
if (window.fbq != null) {
window.fbq('track', 'Lead', {currency: "USD", value: 9.99});
}
}
  • Hey do we have a browser window type object
  • On that object can we find the Facebook object
  • If we can let's use it and call the function to track