You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optional step is to install the type definitions for gtag.js with npm i -D @types/gtag.js.
This is how you can measure information such as the page title and page path using the SvelteKit store.
Because it’s using a store value whenever the page gets updated inside the $: { ... } reactive block we can submit the new page view if gtag exists on window meaning it’s inside the browser context.
Include the Analytics component inside your main layout __layout.svelte making it available on every page.
If you’re using an ad blocker you’re going to see the net::ERR_BLOCKED_BY_CLIENT error in your console as it gets blocked by those extensions — so if you have a tech savvy audience you might want to look into other options.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First, register an account in Home: Google Analytics.
After you fill all the forms, create one website app on that platform.
Click that button and paste the code immediately after the
head
element then everything will be OK.Found one alternative for Svelte:
Create
src/lib/Analytics.svelte
:Optional step is to install the type definitions for
gtag.js
withnpm i -D @types/gtag.js
.This is how you can measure information such as the page title and page path using the SvelteKit store.
Because it’s using a store value whenever the page gets updated inside the
$: { ... }
reactive block we can submit the new page view ifgtag
exists onwindow
meaning it’s inside the browser context.Include the
Analytics
component inside your main layout__layout.svelte
making it available on every page.That’s it! 🎉
Warning
If you’re using an ad blocker you’re going to see the
net::ERR_BLOCKED_BY_CLIENT
error in your console as it gets blocked by those extensions — so if you have a tech savvy audience you might want to look into other options.Beta Was this translation helpful? Give feedback.
All reactions