Created
August 27, 2022 06:26
-
-
Save abhishekpatel946/f003011fcfa991f29b54c66cb2ec0b6e to your computer and use it in GitHub Desktop.
A tiny open-source facebook pixel custom plugin support for analytics. https://getanalytics.io/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Config = { | |
pixelId: string | |
enabled: boolean | |
} | |
let fb: any | |
let fbLoaded = false | |
export default function facebookPixel(config: Config) { | |
return { | |
name: 'facebook-pixel', | |
initialize: async ({ config }) => { | |
const { pixelId } = config | |
if (typeof window !== 'undefined') { | |
await import('react-facebook-pixel') | |
.then((module) => (fb = module.default)) | |
.then(() => { | |
if (!fbLoaded) { | |
fb.init(pixelId, { | |
autoConfig: true, | |
debug: true, | |
}) | |
fbLoaded = true | |
} | |
}) | |
} | |
}, | |
page: (): void => { | |
fb.pageView() | |
}, | |
track: ({ payload }) => { | |
fb.track(payload.event, payload.properties) | |
}, | |
loaded: (): boolean => { | |
return fbLoaded | |
}, | |
} | |
} |
I will make a loom to show you what my implementation looks like, otherwise if you are available for call, let me know
Sure @harrisyn
Hi @abhishekpatel946 and @harrisyn,
Can you share the final code for the FacebookPixel plugin ?
Thanks,
Aldo
@Mexflubber This is the working code and final code. Is it not working for you properly?
FYI I'm using getAnalytics open-source package and this the plug-in for Facebook Pixel. You just need to connect with getAnalytics using the above code as utility and it's doing their job.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sure @harrisyn