Adding analytics to your SaaS Starter project is optional.
Since each analytics platform has different setup instructions, we've created a guide instead of adding it in code.
- Create a PostHog Account
- Install PostHog JS Library
- Run
npm install posthog-jsin your terminal. This will add PostHog dependencies to yourpackage.jsonandpackage-lock.json.
- Run
- Set Up PostHog
- in
src/routes/+layout.svelteadd PostHog to the script section following the Posthog Svelte Guide. Note: ensure you’re logged into PostHog so that the code includes your unique API key automatically.
- in
- Test analytics
- Click around and view a few pages on your site to generate some events. You can view these events in PostHog to ensure tracking is active.
Follow the Google Analytics Guide to add Google Analytics to your project.
The ideal place to add Google Analytics is in src/routes/+layout.svelte.