Vercel analytics in sveltekit layout.svelte file

Hi, I have deployed my first sveltekit app to Vercel. I have added vercel analytics in it.

In the documentation for adding analytics, it is clearly written that the inject function should be put in the “layout.ts” file, but I have put it in the “+layout.svelte” file.
This has not caused any issue yet, and is working fine, but I would like to know if I should move the code to “layout.ts” or is it fine either ways?

This is the snippet

import { dev } from '$app/environment';
import { inject } from '@vercel/analytics';
 
inject({ mode: dev ? 'development' : 'production' });

Link to documentation → Vercel Web Analytics Quickstart

Hi @manansoni77! Using +layout.ts helps to make sure everything is loaded correctly for page rendering. I’d recommend following the docs on this to avoid potentially missing analytics events.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.