svelte-analytics Svelte Themes

Svelte Analytics

Svelte-analytics

Svelte-analytics is an opinionated svelte-kit library to handle analytics easily. It requires svelte 5 and a plausible server. It acts as a server-side only analytics middleware, respect user privacy and do not send any PII.

Features

Planned features

  • None for now!

Usage

Installation

npm install @bhasher/svelte-analytics@latest

Initialization

Svelte-analytics needs to be initialized somewhere and be accessible to the rest of the back-end.

# analytics.ts

import { Analytics } from '@bhasher/Svelte-analytics';

export default new Analytics('my-website', 'https://plausible.domain.tld')

Flows

Every tracking method requires at least a RequestEvent object. The methods are asynchronous, but errors can be caught as for any asynchronous function:

analytics.trackSomething(event).catch(console.warn);

Page view

analytics.trackPlausiblePageview(event);

Register

analytics.trackPlausibleRegister(
    event, 
    'password', // method
    'success' // result
);

Login

analytics.trackPlausibleLogin(
    event,
    'password', // method
    'success' //result
)

Custom

analytics.trackPlausibleCustom(
    event,
    'event-name',
    { 'test': true } // props
)

Top categories

Loading Svelte Themes