trackr

Upgrading from 0.3

What to change when moving @casoon/trackr from 0.3.x to the next release - salt provider, engagement events, database migrations and stricter validation.

The next release of @casoon/trackr changes how sessions are identified and what the client sends. A site that only uses the client needs no change; a server that runs createHandler() or a storage adapter of its own does. All changes are listed under “Breaking” in the changelog.

1. Give the handler a salt provider

Without a salt provider, events carry no session ID, so visitors, sessions and bounces can no longer be counted. Add one to createHandler() and, if you use it, createPixelHandler():

import { createHandler, memorySalt } from "@casoon/trackr/server";

createHandler({ storage, salt: memorySalt() });

memorySalt() fits one long-running server. Serverless functions and Workers need a provider that all instances share, such as salt(siteId, day) from @casoon/trackr-store. Details: Privacy.

If you call createSessionId() yourself, it now takes one object: createSessionId({ ip, ua, salt, siteId, anonymizeIp }) instead of (ip, ua, date).

2. Run the database migrations

With the bundled Postgres adapter, apply the two new migrations before deploying the new version:

psql "$DATABASE_URL" -f node_modules/@casoon/trackr/migrations/002_engagement_events.sql
psql "$DATABASE_URL" -f node_modules/@casoon/trackr/migrations/003_event_hosts.sql

002 allows events of type engagement, 003 adds the host column. Both can run on a database that already has them. Details: Database.

3. Handle engagement events in custom adapters

init() now sends an engagement event with the seconds a page was visible (props.seconds) when the page is hidden or left. A storage adapter of your own receives these events with type: "engagement"; store them or skip them. The GA4 adapter does not forward them.

4. Check what the handler now refuses

The handler answers 400 with a JSON body that lists the fields for events whose ts is not within the last 24 hours, with an unknown type, with overlong fields or with nested props. Clients of this version never send such events; a custom client or server-side sender should be checked against Events.

The portal

The portal (API and dashboard) is part of this repository for the first time. A new install applies its migrations itself. An install of the former trackr-dashboard applies the store migrations up to 0018 before the new version starts: 0006 converts stored absolute URLs to path and query, 0009 recomputes daily totals with the GA4 bounce and session rules. The separate trackr-api worker is gone; the API runs under /api of the dashboard. Details: Running the portal.

Edit this page on GitHub