Analytics

What you don't track, you can't improve - analytics is key, even in rapid prototyping.

This boilerplate offers 2 analytics components: Google Analytics and Plausible Analytics.

If you want to use another analytics tool, you can easily integrate it by following the documentation of the tool you want to use.

Step 1: create a Google Analytics/Plausible Analytics account

In order to start, you need to create an account. The entire process is pretty straight-forward and well documented.

Step 2: get the measurement ID [Google]

For Google Analytics, you need to fill in the `.env` file in the root of the project with the measurement ID.

terminal

Keep in mind that with Google Analytics, you need to have a privacy policy available and a cookie consent alert which is not yet implemented.

If you want to track custom events apart from the page views, see the `/routes/analytics` route which is an example of emitting a custom Google Analytics event.

Step 3: add the analytics component to +layout.svelte

Import the component of your choice and add it to the `+layout.svelte` file.

typescript

And add one of them to your main +layout.svelte:

html

If you want to use PlausibleAnalytics, you need to have the `PUBLIC_DOMAIN_URL` properly set in the `.env` file.