Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,23 @@ instead of `void` (see Changed).
- added: `N event(s) dropped since the last report (<reason>=<n>, ...); getStats() has the totals.` (at most once per flush cycle)
- added: `flush(): N event(s) not delivered yet; kept in memory and retried later.`
- changed: `close(): N event(s) undelivered after ~Xms (budget Yms)` now ends with `: Q queued, F still in flight.` and counts in-flight events
- Warnings for calls dropped because of invalid `track()`/`identify()`/`alias()`/`group()`/`trackPurchase()`
arguments are logged once per client for each kind, then only with `debug: true`. `onDrop` still
fires for every dropped call. Events dropped while sending are reported by the `N event(s) dropped since the last report` line.
- All clients share one process `beforeExit` listener (it was one per client, which triggered
`MaxListenersExceededWarning` when a client was created per request). Each live client is
still flushed once on exit; the listener is removed when the last client is closed.
- The API key prefix warning accepts `sk_` keys as well as `dk_`.
- `examples/stripe-webhook.js` no longer uses the Stripe customer id as `userId`. DATALYR
links Stripe customers only through its own Stripe connection.
- `page()` no longer copies the page `name` into `properties.url` when no url is passed.
Pass `properties.url` to record the page URL.

### Added
- `getStats()`: queued, in-flight and dropped counts, by drop reason.
- `flushTimeout` and `maxRetryDuration` options.
- Drop reason `auth_refused`.
- `trackPurchase()` options accept `externalIds` (same as `track()`), sent only when passed.

## [1.3.4] - 2026-11-14

Expand Down Expand Up @@ -175,17 +187,42 @@ instead of `void` (see Changed).
- "Batching" is a 10-wide concurrency window, not a single batched HTTP request (one POST
per event); the `/batch` endpoint is not used.

## [1.2.1] - 2025-01
## [1.2.3] - 2026-03-20

(entry added later)

### Added
- `eventId` (a UUID) on every event, so the ingest server can de-duplicate.
- `User-Agent: @datalyr/api/<version>` header on every request.
- `alias()` for linking identities (`$alias` events).

### Fixed
- `identify()` sends traits as flat properties instead of wrapping them in `$set`.
- `group()` sends traits as flat properties instead of nesting them under `traits`.

## [1.2.2] - 2026-03-20

(entry added later)

### Fixed
- Events are sent to `https://ingest.datalyr.com/track` instead of `api.datalyr.com`,
which did not record them.
- `SDK_VERSION` constant matches the package version.

### Changed
- README rewritten with the full API reference.

## [1.2.1] - 2026-01-01

### Changed
- Complete README rewrite to match iOS/React Native/Web SDK documentation style

## [1.2.0] - 2025-01
## [1.2.0] - 2026-01-01

### Changed
- Version bump for ecosystem consistency across all Datalyr SDKs

## [1.1.0] - 2025-01
## [1.1.0] - 2025-09-04

### Added
- Anonymous ID support for complete user journey tracking
Expand All @@ -197,6 +234,22 @@ instead of `void` (see Changed).
- track() now supports both legacy (userId, event, properties) and new object signature
- identify() now supports both legacy and new object signature with anonymousId

## [1.0.4] - 2025-08-19

(entry added later) Published to npm; no source history was kept for this version.

## [1.0.3] - 2025-08-19

(entry added later) Published to npm; no source history was kept for this version.

## [1.0.2] - 2025-08-18

(entry added later) Published to npm; no source history was kept for this version.

## [1.0.1] - 2025-08-18

(entry added later) Published to npm; no source history was kept for this version.

## [1.0.0] - 2024-12

### Added
Expand Down
56 changes: 34 additions & 22 deletions examples/stripe-webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
// redelivered purchase is counted once instead of double-counting revenue.
// Also pass `timestamp: event.created` (epoch seconds) so delayed replays land on the
// day the event actually happened, not the day the retry arrived.
//
// IDENTITY: `userId` is YOUR app's user id (the one your client-side identify() uses).
// Never put the Stripe customer id there. DATALYR links Stripe customers to users through
// its own Stripe connection; a `stripe` id sent from this SDK is stored on the event but
// does not link anyone. Keep it in properties if you want to see it on the event.
const express = require('express');
const { Datalyr } = require('@datalyr/api');
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
Expand Down Expand Up @@ -44,15 +49,18 @@ app.post('/webhooks/stripe',
// dropped rather than counted as $0. eventId makes redeliveries idempotent (no
// double-counted revenue); timestamp backdates delayed replays.
await datalyr.trackPurchase(
session.client_reference_id || session.customer,
session.client_reference_id || null,
{
value: session.amount_total / 100,
currency: session.currency,
paymentStatus: session.payment_status,
stripeSessionId: session.id,
customerEmail: session.customer_details?.email
},
{ eventId: event.id, timestamp: event.created }
{
eventId: event.id,
timestamp: event.created
}
);
break;

Expand All @@ -61,7 +69,7 @@ app.post('/webhooks/stripe',

// Track subscription start
await datalyr.track({
userId: subscription.metadata?.userId || subscription.customer,
userId: subscription.metadata?.userId,
event: 'subscription_started',
eventId: event.id,
timestamp: event.created,
Expand All @@ -74,23 +82,25 @@ app.post('/webhooks/stripe',
}
});

// Update user traits
await datalyr.identify(
subscription.metadata?.userId || subscription.customer,
{
subscriptionStatus: 'active',
subscriptionPlan: subscription.items.data[0].price.nickname,
stripeCustomerId: subscription.customer
}
);
// Update user traits (only when you know your own user id)
if (subscription.metadata?.userId) {
await datalyr.identify(
subscription.metadata.userId,
{
subscriptionStatus: 'active',
subscriptionPlan: subscription.items.data[0].price.nickname,
stripeCustomerId: subscription.customer
}
);
}
break;

case 'customer.subscription.deleted':
const canceledSub = event.data.object;

// Track cancellation
await datalyr.track({
userId: canceledSub.metadata?.userId || canceledSub.customer,
userId: canceledSub.metadata?.userId,
event: 'subscription_canceled',
eventId: event.id,
timestamp: event.created,
Expand All @@ -101,22 +111,24 @@ app.post('/webhooks/stripe',
}
});

// Update user traits
await datalyr.identify(
canceledSub.metadata?.userId || canceledSub.customer,
{
subscriptionStatus: 'canceled',
subscriptionEndDate: new Date(canceledSub.ended_at * 1000).toISOString()
}
);
// Update user traits (only when you know your own user id)
if (canceledSub.metadata?.userId) {
await datalyr.identify(
canceledSub.metadata.userId,
{
subscriptionStatus: 'canceled',
subscriptionEndDate: new Date(canceledSub.ended_at * 1000).toISOString()
}
);
}
break;

case 'invoice.payment_failed':
const invoice = event.data.object;

// Track failed payment
await datalyr.track({
userId: invoice.metadata?.userId || invoice.customer,
userId: invoice.metadata?.userId,
event: 'payment_failed',
eventId: event.id,
timestamp: event.created,
Expand Down
Loading