Prepare the test
Use a Node.js 18 or newer app and a LogBrew project that you can read. If you have not sent telemetry before, start with the quickstart. Keep this test separate from customer activity. Install the packages in the app directory:LOGBREW_SERVER_API_KEY,
outside source control. Never put a server key in a browser bundle. An account
access token reads results. It does not configure the SDK.
Decide what one event means
Start with a product question. For example: do users submit checkout after they open it? Give each event a fixed name, an exact trigger, and one place in the app that records it.
Keep event names stable across releases and languages. Do not build names from
an email address, order number, URL, or user-entered text.
Use custom properties with a small set of approved values. For example,
checkout_mode can be guest or signed_in. Do not add a new event name for
each value. Do not send form contents.
Record each business action in one place only. If the browser and the server
both record the same action, the totals double.
Use the correct activity kind
createProductActionAttributes sets analyticsSchemaVersion: 1 and
analyticsKind: "interaction" in the event metadata. Its route template or
screen name sets analyticsSurface. Use a route template, such as
/orders/:id, not a concrete URL.
The event name does not set the kind. An interaction named page_view is
still an interaction. Logs, issues, and spans are not product events. For
other runtimes, see SDK ingestion.
Set users and sessions on each event
- For a signed-in user, set
context.subjectto a stable ID withkind: "user". - For an anonymous visitor, use a separate ID with
kind: "anonymous". - Put the app’s session ID in
context.session.id. Reuse it for the whole session.
Run the example locally
Save this example asproduct-events.mjs. It records five test actions across
anonymous visits, sign-ins, and two users. The client holds only shared
service and deployment context. Automatic delivery is off for this test.
--send. This command sends no request:
previewJson() in an app with real customer context.
Handle login and logout
- Before login, send the current anonymous subject with each event.
- After login, send the user’s stable ID with kind
user. - On logout, stop using that user’s context. Create a new anonymous subject under your privacy policy.
- On an account switch, use the new user’s ID.
Send once and read the results
Set the test project’s server key in the process environment. Run this command once:- 5 interactions, all with session context, on the
/checkoutsurface. - 3 events from users and 2 from anonymous subjects.
- 2 users, 2 anonymous subjects, and 4 sessions.
Test the events in your app
Move the capture calls into the app’s handlers. Keep each event’s meaning, kind, and identity rule. Test with synthetic accounts first.
A local preview tests capture. An accepted batch tests delivery. Neither
shows that the capture call runs at the correct point in your app.
