@traffical/js-client 0.17.0 → 0.18.0
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 +9 -9
- package/dist/client.d.ts +3 -3
- package/dist/client.js +2 -2
- package/dist/exposure-dedup.d.ts +1 -1
- package/dist/exposure-dedup.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/plugins/debug.d.ts +24 -0
- package/dist/plugins/debug.d.ts.map +1 -1
- package/dist/plugins/debug.js +61 -2
- package/dist/plugins/debug.js.map +1 -1
- package/dist/traffical.min.js +2 -2
- package/dist/traffical.min.js.map +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ const traffical = await createTrafficalClient({
|
|
|
29
29
|
orgId: 'org_xxx',
|
|
30
30
|
projectId: 'proj_xxx',
|
|
31
31
|
env: 'production',
|
|
32
|
-
apiKey: '
|
|
32
|
+
apiKey: 'traffical_pk_…',
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// Get parameters
|
|
@@ -67,7 +67,7 @@ traffical.track('checkout_complete', { value: 1 }, { decisionId: decision.decisi
|
|
|
67
67
|
orgId: 'org_xxx',
|
|
68
68
|
projectId: 'proj_xxx',
|
|
69
69
|
env: 'production',
|
|
70
|
-
apiKey: '
|
|
70
|
+
apiKey: 'traffical_pk_…',
|
|
71
71
|
}).then(function(traffical) {
|
|
72
72
|
var params = traffical.getParams({
|
|
73
73
|
context: { userId: 'user_123' },
|
|
@@ -167,7 +167,7 @@ The Traffical DevTools debug plugin uses these methods to let developers force p
|
|
|
167
167
|
## Features
|
|
168
168
|
|
|
169
169
|
- **Error Boundary** - SDK errors never crash your app
|
|
170
|
-
- **Exposure Deduplication** - Same user/
|
|
170
|
+
- **Exposure Deduplication** - Same user/allocation = 1 exposure event per session
|
|
171
171
|
- **Smart Batching** - Events batched and flushed efficiently
|
|
172
172
|
- **Beacon on Unload** - Events sent reliably on page close
|
|
173
173
|
- **Auto Stable ID** - Anonymous user identification via localStorage/cookie
|
|
@@ -187,7 +187,7 @@ const traffical = await createTrafficalClient({
|
|
|
187
187
|
orgId: 'org_xxx',
|
|
188
188
|
projectId: 'proj_xxx',
|
|
189
189
|
env: 'production',
|
|
190
|
-
apiKey: '
|
|
190
|
+
apiKey: 'traffical_pk_…',
|
|
191
191
|
plugins: [
|
|
192
192
|
createDOMBindingPlugin({
|
|
193
193
|
observeMutations: true, // Watch for DOM changes (SPA support)
|
|
@@ -218,7 +218,7 @@ The plugin:
|
|
|
218
218
|
|
|
219
219
|
### Redirect Plugin
|
|
220
220
|
|
|
221
|
-
Run URL split tests (redirect
|
|
221
|
+
Run URL split tests (redirect policies) where visitors are redirected to different landing page allocations. The redirect plugin automatically triggers a decision on init, performs the redirect, and sets an attribution cookie. The attribution plugin ensures conversions on the destination page are attributed back to the policy.
|
|
222
222
|
|
|
223
223
|
```typescript
|
|
224
224
|
import {
|
|
@@ -231,7 +231,7 @@ const traffical = await createTrafficalClient({
|
|
|
231
231
|
orgId: 'org_xxx',
|
|
232
232
|
projectId: 'proj_xxx',
|
|
233
233
|
env: 'production',
|
|
234
|
-
apiKey: '
|
|
234
|
+
apiKey: 'traffical_pk_…',
|
|
235
235
|
plugins: [
|
|
236
236
|
createRedirectPlugin(),
|
|
237
237
|
createRedirectAttributionPlugin(),
|
|
@@ -242,7 +242,7 @@ const traffical = await createTrafficalClient({
|
|
|
242
242
|
// On entry pages, it redirects. On other pages, it's a no-op.
|
|
243
243
|
|
|
244
244
|
// Track goals as usual — the attribution plugin injects
|
|
245
|
-
// redirect
|
|
245
|
+
// redirect policy metadata into every track() call.
|
|
246
246
|
traffical.track('add_to_cart', { value: 29.99 });
|
|
247
247
|
```
|
|
248
248
|
|
|
@@ -281,9 +281,9 @@ Track goal events from a separate GTM tag (e.g., triggered on "Add to Cart" clic
|
|
|
281
281
|
|
|
282
282
|
1. **Init** — The redirect plugin's `onInitialize` hook receives the client and calls `decide()` automatically.
|
|
283
283
|
|
|
284
|
-
2. **Entry page** — `onBeforeDecision` injects `url.pathname` into the context. The policy condition (e.g., `url.pathname startsWith /products/pillow`) matches, `redirect.url` resolves to the
|
|
284
|
+
2. **Entry page** — `onBeforeDecision` injects `url.pathname` into the context. The policy condition (e.g., `url.pathname startsWith /products/pillow`) matches, `redirect.url` resolves to the allocation's URL. `onDecision` writes an attribution cookie (`traffical_rdr`) and calls `window.location.replace()`.
|
|
285
285
|
|
|
286
|
-
3. **
|
|
286
|
+
3. **Destination page** — The SDK loads again, `decide()` runs, but the policy condition doesn't match the new URL, so `redirect.url` stays empty and no redirect happens. The redirect-attribution plugin reads the `traffical_rdr` cookie and injects the policy metadata into every `track()` call.
|
|
287
287
|
|
|
288
288
|
#### Configuration
|
|
289
289
|
|
package/dist/client.d.ts
CHANGED
|
@@ -151,7 +151,7 @@ export interface TrafficalClientOptions {
|
|
|
151
151
|
disableCloudEvents?: boolean;
|
|
152
152
|
/**
|
|
153
153
|
* When true, assignment logger calls are deduplicated per session
|
|
154
|
-
* (same unit+policy+
|
|
154
|
+
* (same unit+policy+allocation won't fire again). Default: true.
|
|
155
155
|
*/
|
|
156
156
|
deduplicateAssignmentLogger?: boolean;
|
|
157
157
|
/**
|
|
@@ -275,7 +275,7 @@ export declare class TrafficalClient<TEvents extends TrackEventMap = TrackEventM
|
|
|
275
275
|
decide<T extends Record<string, ParameterValue>>(options: DecideOptions<T>): DecisionResult;
|
|
276
276
|
/**
|
|
277
277
|
* Tracks an exposure event.
|
|
278
|
-
* Automatically deduplicates
|
|
278
|
+
* Automatically deduplicates exposure events for the same user/allocation.
|
|
279
279
|
*
|
|
280
280
|
* Skips layers marked `attributionOnly` — those were resolved for
|
|
281
281
|
* attribution/assignment purposes only (no parameters were requested
|
|
@@ -419,7 +419,7 @@ export declare class TrafficalClient<TEvents extends TrackEventMap = TrackEventM
|
|
|
419
419
|
* - "cumulative": Collects layers from ALL cached decisions for this unit,
|
|
420
420
|
* deduplicated by layerId:policyId (last-write-wins). This ensures cross-page
|
|
421
421
|
* funnels (e.g., catalog -> PDP -> checkout) attribute correctly to all
|
|
422
|
-
*
|
|
422
|
+
* policies the user is exposed to. For per-entity dynamic allocation
|
|
423
423
|
* policies, only the most recent allocation is kept to avoid attributing
|
|
424
424
|
* rewards to allocations from other entities (e.g., different products).
|
|
425
425
|
*
|
package/dist/client.js
CHANGED
|
@@ -464,7 +464,7 @@ export class TrafficalClient {
|
|
|
464
464
|
// ===========================================================================
|
|
465
465
|
/**
|
|
466
466
|
* Tracks an exposure event.
|
|
467
|
-
* Automatically deduplicates
|
|
467
|
+
* Automatically deduplicates exposure events for the same user/allocation.
|
|
468
468
|
*
|
|
469
469
|
* Skips layers marked `attributionOnly` — those were resolved for
|
|
470
470
|
* attribution/assignment purposes only (no parameters were requested
|
|
@@ -1065,7 +1065,7 @@ export class TrafficalClient {
|
|
|
1065
1065
|
* - "cumulative": Collects layers from ALL cached decisions for this unit,
|
|
1066
1066
|
* deduplicated by layerId:policyId (last-write-wins). This ensures cross-page
|
|
1067
1067
|
* funnels (e.g., catalog -> PDP -> checkout) attribute correctly to all
|
|
1068
|
-
*
|
|
1068
|
+
* policies the user is exposed to. For per-entity dynamic allocation
|
|
1069
1069
|
* policies, only the most recent allocation is kept to avoid attributing
|
|
1070
1070
|
* rewards to allocations from other entities (e.g., different products).
|
|
1071
1071
|
*
|
package/dist/exposure-dedup.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ExposureDeduplicator - Prevents duplicate exposure events.
|
|
3
3
|
*
|
|
4
|
-
* Same user seeing same
|
|
4
|
+
* Same user seeing the same allocation should only count as 1 exposure.
|
|
5
5
|
* Uses session-based deduplication with localStorage persistence.
|
|
6
6
|
*/
|
|
7
7
|
import type { StorageProvider } from "./storage.js";
|
package/dist/exposure-dedup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ExposureDeduplicator - Prevents duplicate exposure events.
|
|
3
3
|
*
|
|
4
|
-
* Same user seeing same
|
|
4
|
+
* Same user seeing the same allocation should only count as 1 exposure.
|
|
5
5
|
* Uses session-based deduplication with localStorage persistence.
|
|
6
6
|
*/
|
|
7
7
|
const STORAGE_KEY = "exposure_dedup";
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Features:
|
|
7
7
|
* - Error boundary wrapping (P0) - SDK errors never crash your app
|
|
8
|
-
* - Exposure deduplication (P0) - Same user/
|
|
8
|
+
* - Exposure deduplication (P0) - Same user/allocation = 1 exposure event
|
|
9
9
|
* - Smart event batching (P1) - Batches events, uses sendBeacon on unload
|
|
10
10
|
* - Plugin system (P2) - Extensible via plugins
|
|
11
11
|
* - DOM binding plugin - Auto-apply parameters to DOM elements
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Features:
|
|
7
7
|
* - Error boundary wrapping (P0) - SDK errors never crash your app
|
|
8
|
-
* - Exposure deduplication (P0) - Same user/
|
|
8
|
+
* - Exposure deduplication (P0) - Same user/allocation = 1 exposure event
|
|
9
9
|
* - Smart event batching (P1) - Batches events, uses sendBeacon on unload
|
|
10
10
|
* - Plugin system (P2) - Extensible via plugins
|
|
11
11
|
* - DOM binding plugin - Auto-apply parameters to DOM elements
|
package/dist/plugins/debug.d.ts
CHANGED
|
@@ -53,6 +53,18 @@ export interface DebugState {
|
|
|
53
53
|
lastDecisionId: string | null;
|
|
54
54
|
/** Parameter overrides currently applied by the debug plugin. */
|
|
55
55
|
overrides: Record<string, unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* Context attributes the debug plugin merges into every decision's context
|
|
58
|
+
* (on top of whatever the host app passes). Lets an inspector satisfy
|
|
59
|
+
* targeting conditions the app itself never sets, e.g. `testMode exists`.
|
|
60
|
+
*/
|
|
61
|
+
contextOverrides: Record<string, unknown>;
|
|
62
|
+
/**
|
|
63
|
+
* The context of the last real decision, as the app passed it (after the
|
|
64
|
+
* client's unit-key enrichment, before context overrides). `null` until the
|
|
65
|
+
* app has decided at least once.
|
|
66
|
+
*/
|
|
67
|
+
lastContext: Record<string, unknown> | null;
|
|
56
68
|
}
|
|
57
69
|
export interface TrafficalDebugInstance {
|
|
58
70
|
readonly id: string;
|
|
@@ -72,6 +84,18 @@ export interface TrafficalDebugInstance {
|
|
|
72
84
|
clearOverride(key: string): void;
|
|
73
85
|
clearAllOverrides(): void;
|
|
74
86
|
getOverrides(): Record<string, unknown>;
|
|
87
|
+
/**
|
|
88
|
+
* Replace the context attributes merged into every decision. Re-decides
|
|
89
|
+
* immediately. Pass `{}` to clear.
|
|
90
|
+
*/
|
|
91
|
+
setContextOverrides(context: Record<string, unknown>): void;
|
|
92
|
+
getContextOverrides(): Record<string, unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* Re-run the app's last decision (same context and parameter set) so the
|
|
95
|
+
* inspector shows what the app would resolve right now. If the page uses
|
|
96
|
+
* the OpenFeature provider, the OpenFeature context is re-set so hooks
|
|
97
|
+
* bound to `PROVIDER_CONTEXT_CHANGED` re-render too.
|
|
98
|
+
*/
|
|
75
99
|
reDecide(): void;
|
|
76
100
|
refresh(): Promise<void>;
|
|
77
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/plugins/debug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EACV,YAAY,
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/plugins/debug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EACV,YAAY,EAMZ,eAAe,EAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK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AAM;QACd,mBAAmB,CAAC,EAAE,sBAAsB,CAAC;QAC7C,uBAAuB,CAAC,EAAE,OAAO,EAAE,CAAC;KACrC;CACF;AAqFD,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE,kBAAuB,GAC/B,eAAe,CAoRjB"}
|
package/dist/plugins/debug.js
CHANGED
|
@@ -67,6 +67,21 @@ function emitRegistryEvent(event) {
|
|
|
67
67
|
// Helpers
|
|
68
68
|
// ---------------------------------------------------------------------------
|
|
69
69
|
let _idCounter = 0;
|
|
70
|
+
/**
|
|
71
|
+
* The OpenFeature web SDK stores its API singleton on globalThis under a
|
|
72
|
+
* well-known symbol. Nudging its context makes `@traffical/openfeature-web`
|
|
73
|
+
* re-resolve every flag (through this client's `decide`, and therefore
|
|
74
|
+
* through the debug plugin's `onBeforeDecision`) and emit
|
|
75
|
+
* `PROVIDER_CONTEXT_CHANGED`, which is what host-app hooks re-render on.
|
|
76
|
+
*/
|
|
77
|
+
const OPENFEATURE_API_SYMBOL = Symbol.for("@openfeature/web-sdk/api");
|
|
78
|
+
function getOpenFeatureApi() {
|
|
79
|
+
const api = globalThis[OPENFEATURE_API_SYMBOL];
|
|
80
|
+
if (api && typeof api.getContext === "function" && typeof api.setContext === "function") {
|
|
81
|
+
return api;
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
70
85
|
function generateId() {
|
|
71
86
|
return `traffical_${Date.now().toString(36)}_${(++_idCounter).toString(36)}`;
|
|
72
87
|
}
|
|
@@ -87,6 +102,9 @@ export function createDebugPlugin(options = {}) {
|
|
|
87
102
|
let _layers = [];
|
|
88
103
|
let _lastDecisionId = null;
|
|
89
104
|
let _effectiveUnitKey = null;
|
|
105
|
+
let _contextOverrides = {};
|
|
106
|
+
let _lastContext = null;
|
|
107
|
+
let _lastDefaults = null;
|
|
90
108
|
const _events = [];
|
|
91
109
|
let _stateListeners = [];
|
|
92
110
|
let _eventListeners = [];
|
|
@@ -100,6 +118,8 @@ export function createDebugPlugin(options = {}) {
|
|
|
100
118
|
layers: [..._layers],
|
|
101
119
|
lastDecisionId: _lastDecisionId,
|
|
102
120
|
overrides: _client?.getOverrides?.() ?? {},
|
|
121
|
+
contextOverrides: { ..._contextOverrides },
|
|
122
|
+
lastContext: _lastContext ? { ..._lastContext } : null,
|
|
103
123
|
};
|
|
104
124
|
}
|
|
105
125
|
function notifyStateListeners() {
|
|
@@ -134,9 +154,30 @@ export function createDebugPlugin(options = {}) {
|
|
|
134
154
|
}
|
|
135
155
|
}
|
|
136
156
|
function triggerReDecide() {
|
|
137
|
-
if (_client)
|
|
157
|
+
if (!_client)
|
|
158
|
+
return;
|
|
159
|
+
// Replay the app's last real decision. Unknown parameter keys keep the
|
|
160
|
+
// values we pass; known ones are re-resolved from the bundle, so the
|
|
161
|
+
// previous assignments are a faithful stand-in for the app's defaults.
|
|
162
|
+
// Before the app has decided once there is nothing to replay: an empty
|
|
163
|
+
// decision still refreshes layer/bucket info without resolving params.
|
|
164
|
+
try {
|
|
165
|
+
_client.decide({
|
|
166
|
+
context: _lastContext ? { ..._lastContext } : {},
|
|
167
|
+
defaults: _lastDefaults ? { ..._lastDefaults } : {},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
// Best-effort
|
|
172
|
+
}
|
|
173
|
+
// OpenFeature-hosted apps resolve through the provider's bound context,
|
|
174
|
+
// not through the decision above. Re-setting the same context forces the
|
|
175
|
+
// provider to clear its memo and re-resolve, and fires
|
|
176
|
+
// PROVIDER_CONTEXT_CHANGED so the app's hooks pick up the new values.
|
|
177
|
+
const openFeature = getOpenFeatureApi();
|
|
178
|
+
if (openFeature) {
|
|
138
179
|
try {
|
|
139
|
-
|
|
180
|
+
void openFeature.setContext({ ...openFeature.getContext() }).catch(() => { });
|
|
140
181
|
}
|
|
141
182
|
catch {
|
|
142
183
|
// Best-effort
|
|
@@ -208,6 +249,14 @@ export function createDebugPlugin(options = {}) {
|
|
|
208
249
|
getOverrides() {
|
|
209
250
|
return _client?.getOverrides?.() ?? {};
|
|
210
251
|
},
|
|
252
|
+
setContextOverrides(context) {
|
|
253
|
+
_contextOverrides = { ...context };
|
|
254
|
+
notifyStateListeners();
|
|
255
|
+
triggerReDecide();
|
|
256
|
+
},
|
|
257
|
+
getContextOverrides() {
|
|
258
|
+
return { ..._contextOverrides };
|
|
259
|
+
},
|
|
211
260
|
reDecide() {
|
|
212
261
|
triggerReDecide();
|
|
213
262
|
},
|
|
@@ -242,7 +291,14 @@ export function createDebugPlugin(options = {}) {
|
|
|
242
291
|
debugInstance.meta.env = bundle.env;
|
|
243
292
|
notifyStateListeners();
|
|
244
293
|
},
|
|
294
|
+
onBeforeDecision(context) {
|
|
295
|
+
_lastContext = { ...context };
|
|
296
|
+
if (Object.keys(_contextOverrides).length === 0)
|
|
297
|
+
return;
|
|
298
|
+
return { ...context, ..._contextOverrides };
|
|
299
|
+
},
|
|
245
300
|
onDecision(decision) {
|
|
301
|
+
_lastDefaults = { ...decision.assignments };
|
|
246
302
|
_assignments = { ...decision.assignments };
|
|
247
303
|
_layers = decision.metadata?.layers ? [...decision.metadata.layers] : [];
|
|
248
304
|
_lastDecisionId = decision.decisionId;
|
|
@@ -273,6 +329,9 @@ export function createDebugPlugin(options = {}) {
|
|
|
273
329
|
}
|
|
274
330
|
_stateListeners = [];
|
|
275
331
|
_eventListeners = [];
|
|
332
|
+
_contextOverrides = {};
|
|
333
|
+
_lastContext = null;
|
|
334
|
+
_lastDefaults = null;
|
|
276
335
|
_client = null;
|
|
277
336
|
},
|
|
278
337
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/plugins/debug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/plugins/debug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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