Anyone one have any insight on how to integrate a Meta/FB Pixel with a SolidStart site?

I saw resources how to implement it with next but, the package seemed slightly different from SolidStart
8 Replies
Alex Lohr
Alex Lohr2y ago
We have @solid-primitives/script-loader to interact with external scripts.
import { createScriptLoader } from "@solid-primitives/script-loader";

createScriptLoader({
url: 'https://connect.facebook.net/en_US/fbevents.js',
onLoad: () => {
window.fbq('init', '{your-pixel-id-goes-here}');
window.fbq('track', 'PageView');
}
});
import { createScriptLoader } from "@solid-primitives/script-loader";

createScriptLoader({
url: 'https://connect.facebook.net/en_US/fbevents.js',
onLoad: () => {
window.fbq('init', '{your-pixel-id-goes-here}');
window.fbq('track', 'PageView');
}
});
narmia
narmiaOP2y ago
Thanks! Would I need to wrap that within a createEffect or, onMount for it to fire properly?
Alex Lohr
Alex Lohr2y ago
Neither. You can just put it into the top level of your component, or even global scope.
narmia
narmiaOP2y ago
When I do I get this error. Tried looking at stsack overflow but can't find an answer that fixes it. uncaught TypeError: Cannot use 'in' operator to search for 'Symbol(solid-proxy)' in https://connect.facebook.net/en_US/fbe
Alex Lohr
Alex Lohr2y ago
Sorry, I'm a bit short on time; need to check later. Sorry, wrong argument syntax.
narmia
narmiaOP2y ago
Thanks, not sure what I'm doing wrong lol. Added it to the index page of my SolidStart app and it just breaks the entire site
Daniel Sousa @TutoDS
How can this works for google tag manager? And other question, how to type window to have fbq? Did you face this:window.fbq is not a function
Alex Lohr
Alex Lohr4w ago
declare global {
interface Window {
fbq: [insert type here];
}
}
declare global {
interface Window {
fbq: [insert type here];
}
}
Want results from more Discord servers?
Add your server