Skip to main content
One package sends events in from the browser or Node, and sends transactional email from your server. This page describes version 0.2.0 and the identity-token options that come after it; the source and every release are on GitHub. Both entries have the same version. A web bundle that imports the main entry never holds the server entry.

Send events

1

Install

2

Create the client

Pass your public key. The client refuses a secret key.
3

Identify and track

Call identify when you know who the person is, and track when something happens. Name events object.action in lower case; Events lists the fields each call takes.
4

Forget the person on sign-out

Call reset() when someone logs out. It forgets the person and starts a new anonymous id.
Both entries are ES modules. Node 22.12 or later runs them, and a CommonJS project loads them with require() on that version. Browsers need nothing extra.
The SDK keeps the identified person, and the anonymous id their earlier visits are linked to, in the browser’s storage, so they stay identified after a page load. Without reset(), the next person on the same browser is tracked as the previous one: their events go on the previous profile, and can start journeys that email the previous person.

Identity token

When your workspace’s identity verification is on, a call that names a person needs a token your server signs for that person. Give the SDK the token and it sends it for you. Identity verification shows how to sign one.
The token options need a version of @maqetin/sdk-js newer than 0.2.0.
  • The SDK sends the token in the Maqetin-Identity-Token header with each batch that names its person, never in the events. A batch holds one person’s calls, or anonymous calls only.
  • It keeps the token in memory only. After a page load it has the person but no token, so it asks onIdentityTokenExpiring before it sends that person’s calls.
  • It asks 60 seconds before exp (or at half the time left, for a shorter token), when there is none, and when the gateway refuses one. Return the token, a promise of it, or nothing and call setIdentityToken later.
  • A refused batch is kept, in order, and sent again with the same message ids when a different token for that person arrives. After maxRetries more refused tokens in a row the calls are dropped and reported to onError with the kind identity. With no onIdentityTokenExpiring, a refused token drops its batch at once.
  • identify with a token for another person, or a value that is not a JWT with sub and exp, is refused and reported. reset() forgets the token.
  • A track with options.userId for another person goes without a token.

Methods

Good to know:
  • The client sends a page view when it starts and when a single-page app moves to a new path (pushState, replaceState, back and forward). A change of the query string or the fragment alone is not a new page. Set autoPageViews: false to send page views yourself with page().
  • The first view is sent when the client starts, so its title can be empty if you load the SDK in <head>. The referrer is the page the visitor came from when the site loaded; in a single-page app it stays the same between routes, because the browser does not change it.
  • A call is fixed when you make it. Changing the properties object after track does not change the event.
  • Queued calls are sent when the page closes or goes to the background (pagehide and visibilitychange).

Options

Limits

When a call is dropped

Every dropped call is reported to onError as a MaqetinError. No message the SDK reports or writes holds the key; reason text that holds key text is dropped. The SDK refuses a call alone, and reports it to onError, when it holds a value JSON cannot hold (a cycle, a BigInt), is over 32 KiB as JSON, has a typed trait of the wrong type, or has a timestamp that is not a valid Date. The rest of its batch is sent.

Send email from your server

The message

Server options

Privacy and device storage

What the SDK collects, and every read and write it makes on the device.

Send through your own domain

Keep events flowing when a blocker list names the Maqetin host.