I want to integrate Mixpanel to my SvelteKit project by following official documentation at https://developer.mixpanel.com/docs/javascript-quickstart
To integrate I have initilise mixpanel using code
import mixpanel from 'mixpanel-browser';
mixpanel.init('YOUR_TOKEN', {debug: true});
mixpanel.track('test event');
Where should I add this mixpanel initialisation so I can track events on my desired pages?
My project already have +layout.server.js
and I can not initilise mixpanel in this file becase this will run on server side.
Now I have choice of +layout.js
and +layout.svelte
.
If I choose to use +layout.js
then it will conflict with +layout.server.js
If I choose to use +layout.svelte
then I am not sure if I can expose mixpanel globally to child pages.
So what should be right way to integrate mixpanel if +layout.server.js
is present in project?