Trying to implement Facebook Pixel for event tracking on the client side within my NextJS app-router project.
Following the instructions provided in the NextJS pixel repository: https://github.com/vercel/next.js/tree/canary/examples/with-facebook-pixel/app
I've placed a pixel.js
script in the public/scripts
directory.
Within my layout.tsx
, I have incorporated the FacebookPixel
Component.
I also have a file named fpixel.js
in my library folder.
However, whenever I try to log an event using the pixel, an error occurs. Usage:
import * as fbq from "../../../library/third-party/fpixel"
// ...
fbq.event("Purchase", { currency: "GBP", value: 1 });
The error message displayed in the browser is:
TypeError: window.fbq is not a function
This error points to the fpixel.js
file, which conveniently exports the event
method for our use.
Why am I encountering this issue? Any assistance would be greatly appreciated.