I've entered a Facebook pixel in the gatsby plugin settings (it's copied from Facebook, to ensure there are no typos).
I can't see the Facebook pixel code anywhere. I've tried both with production and development settings and only production.
In Facebook business manager I also get the notice that the pixel isn't active. The plugin simply doesn't seem to do anything with the pixelId.
After some digging around in the plugin. I extracted the code that should be the result of having the tracking Id present in the plugin, and run it directly in the onClientEntry
in gatsby-browser.js
in the plugin:
!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');
window.fbq("init", "[FACEBOOK_PIXEL_ID]");
window.fbq("track", "PageView");
This works fine. Not really a permanent solution 😅 But works as a quick fix.
Something is definitely wrong in the Facebook pixel confirmation chain in the plugin. Let me know if I can help in some other way. I'll try and take another dive in the code in a couple of days if no one else has any suggestions 😄
EDIT
I'm tired and a was a little bit hasty... obviously this doesn't work when deploying remotely since plugins are installed on build. So This only works locally to see that there is something wrong with the Facebook pixel in the plugin.
Temporary fix
Putting the following in my gatsby-browser.js
solves the issue for now.
exports.onClientEntry = () => {
/* eslint-disable */
!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');
/* eslint-enable */
window.fbq("init", process.env.FACBOOK_PIXEL_ID);
window.fbq("track", "PageView");
}
Versions
gatsby: 3.5.1,
gatsby-plugin-gdpr-cookies: 2.0.0,
react-cookie-consent: 6.2.4,