@anyreplay/browser 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,7 +57,7 @@ from its setup page; it loads the same code from `cdn.anyreplay.com`.
57
57
  | `createRecorder(options)` | Starts recording (or waits for consent) and returns a handle |
58
58
  | `handle.track(name, properties?)` | Tags this moment; `name` is 1–64 chars of `[A-Za-z0-9_.:-]`, properties a JSON object ≤ 4 KB |
59
59
  | `handle.trackError(error)` | Records an error you caught yourself, redacted, and marks the session as having one |
60
- | `handle.identify({ userId?, email? })` | Attaches your user id to the session |
60
+ | `handle.identify({ userId?, email? })` | Attaches your user id to the session; held until the session's first chunk is accepted, then sent once |
61
61
  | `handle.consent(true)` | Starts recording when `requireConsent: true`; `consent(false)` removes what was stored and stops (before recording started, a later `consent(true)` still starts it) |
62
62
  | `handle.status()` | `idle`, `awaiting-consent`, `recording`, `sampled-out` or `stopped` |
63
63
  | `handle.flush()` | Sends what is buffered now; resolves when delivered |
package/dist/index.cjs CHANGED
@@ -5120,7 +5120,7 @@ var Transport = class {
5120
5120
 
5121
5121
  // src/version.ts
5122
5122
  var SDK_NAME = "@anyreplay/browser";
5123
- var SDK_VERSION = true ? "0.2.2" : "0.0.0-dev";
5123
+ var SDK_VERSION = true ? "0.2.3" : "0.0.0-dev";
5124
5124
  var PLATFORM = "web";
5125
5125
 
5126
5126
  // src/visitor.ts
@@ -5246,7 +5246,10 @@ function createRecorder(rawOptions, shell) {
5246
5246
  let assets;
5247
5247
  let pageCount = 0;
5248
5248
  let pendingTraits;
5249
- const sendIdentity = (who, traits) => {
5249
+ let traitsAwaitingSession;
5250
+ let traitsToRetry;
5251
+ let sessionDelivered = false;
5252
+ const postIdentity = (who, traits, retryIfUnapplied) => {
5250
5253
  void fetch(`${options.ingestUrl}/v1/ingest/identify`, {
5251
5254
  method: "POST",
5252
5255
  headers: { "Content-Type": "application/json" },
@@ -5257,9 +5260,33 @@ function createRecorder(rawOptions, shell) {
5257
5260
  ...traits,
5258
5261
  ...options.appId ? { appId: options.appId } : {}
5259
5262
  })
5263
+ }).then(async (response) => {
5264
+ if (!retryIfUnapplied || response.status !== 202) return;
5265
+ const reply = await response.json();
5266
+ if (reply.applied === false && identity === who && !traitsAwaitingSession && !traitsToRetry) {
5267
+ traitsToRetry = traits;
5268
+ }
5260
5269
  }).catch(() => {
5261
5270
  });
5262
5271
  };
5272
+ const sendIdentity = (who, traits) => {
5273
+ traitsToRetry = void 0;
5274
+ if (!sessionDelivered) {
5275
+ traitsAwaitingSession = { ...traitsAwaitingSession, ...traits };
5276
+ return;
5277
+ }
5278
+ postIdentity(who, traits, true);
5279
+ };
5280
+ const noteDelivered = (channel) => {
5281
+ if (channel !== transport || !identity) return;
5282
+ sessionDelivered = true;
5283
+ const waiting = traitsAwaitingSession;
5284
+ const retry = traitsToRetry;
5285
+ traitsAwaitingSession = void 0;
5286
+ traitsToRetry = void 0;
5287
+ if (waiting) postIdentity(identity, waiting, true);
5288
+ else if (retry) postIdentity(identity, retry, false);
5289
+ };
5263
5290
  const collectMeta = (who) => {
5264
5291
  var _a, _b;
5265
5292
  return {
@@ -5368,6 +5395,7 @@ function createRecorder(rawOptions, shell) {
5368
5395
  initialSeq: who.nextSeq
5369
5396
  },
5370
5397
  {
5398
+ onSent: () => noteDelivered(channel),
5371
5399
  onSeqReserved: (next) => {
5372
5400
  var _a;
5373
5401
  reserveSeq(session, next);
@@ -5511,6 +5539,8 @@ function createRecorder(rawOptions, shell) {
5511
5539
  identity = void 0;
5512
5540
  }
5513
5541
  pendingTraits = void 0;
5542
+ traitsAwaitingSession = void 0;
5543
+ traitsToRetry = void 0;
5514
5544
  pending.length = 0;
5515
5545
  forgetVisitor(local, session);
5516
5546
  },