I have the pixel script and have added it to the _document.js of my Next.js project. The script is loading fine but i want it to fire on a specific event like a button click.
Now there are plenty of examples on stackoverflow and they all
but i’m unable to implement them in my project (still new to react)
<button onClick="fbq('track', 'Purchase');">Button Text</button>
and
<script>
function onClick() {
fbq('track', 'Purchase');
};
</script>
i always get error around fbq and window.
if (typeof window !== "undefined") {
if (window.fbq != null) {
window.fbq('track', 'PageView')
}
}
for some reason it is unable to identify window or FBQ,
how to tackle this?