2.2.1 • Published 6 months ago

@olros/stats v2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Stats

Simple tool to track analytics to Stats (https://stats.olafros.com). This package is only exported as an ESM-module.

Usage

Create an instance of Stats:

// utils/stats.ts
import { Stats } from '@olros/stats';

const TEAM = 'your-team-ID';
const PROJECT = 'your-project-ID';

export const stats = Stats({ team: TEAM, project: PROJECT });`}

Use the stats.pageview-method on each pagenavigation to track pageviews. Example from React with React-Router:

// route.ts
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

import { stats } from 'utils/stats'; // Import the stats-instance

// ...

const location = useLocation();

useEffect(() => {
  stats.pageview();
}, [location.pathname, location.search]);

Use the stats.event-method to track custom events:

// route.ts
import { stats } from 'utils/stats'; // Import the stats-instance

// ...

const handleClick = () => {
  stats.event('buy');
}

Configuration

Stats<CustomEvents>():

  • team: The team-ID, required
  • project: The project-ID, required
  • baseUrl: URL of Stats. Must be set if self-hosted. Defaults to https://stats.olafros.com
  • allowLocalhost: Send events from localhost, defaults to false

The CustomEvents-generic can be used to optionally typecheck which custom events are allowed. By default all strings are accepted:

const statsWithGenerics = Stats<'buy' | 'save'>(init);

statsWithGenerics.event('buy'); // ✅ No errors
statsWithGenerics.event('delete'); // ❌ Error

const statsWithoutGenerics = Stats(init);

statsWithoutGenerics.event('delete'); // ✅ No errors
2.2.1

6 months ago

2.2.0

6 months ago

2.1.1

6 months ago

2.1.0

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago