@snowplow/signals-browser-plugin 0.0.1 → 0.1.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/dist/index.module.d.ts +22 -22
- package/dist/index.module.js +27 -24
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +27 -24
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +2 -2
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.module.d.ts
CHANGED
|
@@ -25,21 +25,21 @@ type Intervention = {
|
|
|
25
25
|
*/
|
|
26
26
|
version: number;
|
|
27
27
|
/**
|
|
28
|
-
* The complete or requested set of attributes for the
|
|
28
|
+
* The complete or requested set of attributes for the attribute key this intervention was triggered against an their values when it was triggered.
|
|
29
29
|
*/
|
|
30
30
|
attributes: Record<string, OneOrMore<string | number | boolean>>;
|
|
31
31
|
/**
|
|
32
|
-
* Information about the
|
|
32
|
+
* Information about the attribute key that triggered this intervention or is intended to receive it.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
target_attribute_key?: {
|
|
35
35
|
/**
|
|
36
|
-
* The name/type of
|
|
36
|
+
* The name/type of attribute key that is the target/triggerer of this intervention.
|
|
37
37
|
*/
|
|
38
|
-
name:
|
|
38
|
+
name: AttributeKeyName;
|
|
39
39
|
/**
|
|
40
|
-
* The specific identifier for the instance of type `
|
|
40
|
+
* The specific identifier for the instance of type `attributeKeyName` that is the target/triggerer of this intervention.
|
|
41
41
|
*/
|
|
42
|
-
id?:
|
|
42
|
+
id?: AttributeKeyId;
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
@@ -55,13 +55,13 @@ type JSONPointer = '' | `/${string}`;
|
|
|
55
55
|
*/
|
|
56
56
|
type JSONPointerList = OneOrMore<JSONPointer>;
|
|
57
57
|
/**
|
|
58
|
-
* Handle for an
|
|
58
|
+
* Handle for an attribute key type to request Interventions for. The name is paired with an AttributeKeyId as URL parameters in the request for Interventions.
|
|
59
59
|
*/
|
|
60
|
-
type
|
|
60
|
+
type AttributeKeyName = string;
|
|
61
61
|
/**
|
|
62
|
-
* An identifier for a specific
|
|
62
|
+
* An identifier for a specific attribute key instance.
|
|
63
63
|
*/
|
|
64
|
-
type
|
|
64
|
+
type AttributeKeyId = string;
|
|
65
65
|
/**
|
|
66
66
|
* Unique name/identifier for an Intervention handler.
|
|
67
67
|
*/
|
|
@@ -83,13 +83,13 @@ type SignalsInterventionConfiguration = {
|
|
|
83
83
|
*/
|
|
84
84
|
apiPath?: string;
|
|
85
85
|
/**
|
|
86
|
-
* A definition of
|
|
86
|
+
* A definition of attribute key types and JSON Pointers to extract the ID values from. These will be extracted from events as they are tracked to update the Intervention request as values are updated.
|
|
87
87
|
*/
|
|
88
|
-
|
|
88
|
+
attributeKeyTargets?: Record<AttributeKeyName, JSONPointerList>;
|
|
89
89
|
/**
|
|
90
|
-
* An explicit set of
|
|
90
|
+
* An explicit set of attribute key types and corresponding IDs to request interventions for.
|
|
91
91
|
*/
|
|
92
|
-
|
|
92
|
+
attributeKeyIds?: Record<AttributeKeyName, AttributeKeyId>;
|
|
93
93
|
/**
|
|
94
94
|
* Timeout duration to wait for the initial API to accept the Intervention request.
|
|
95
95
|
*/
|
|
@@ -135,20 +135,20 @@ interface FetcherFactory {
|
|
|
135
135
|
/**
|
|
136
136
|
* A `Fetcher` is expected to react to calls to `configure()` and use the provided information to subscribe to Interventions.
|
|
137
137
|
* When interventions are received, a `Fetcher` is expected to call the `dispatch` callback that was provided to the `FetchFactory` that constructed the `Fetcher` and provide the `BrowserTracker` to measure events with.
|
|
138
|
-
* `update()` will be called when new Snowplow events are observed, or explicit
|
|
138
|
+
* `update()` will be called when new Snowplow events are observed, or explicit attribute key IDs are provided. It should update the connection so Interventions may be received for new attribute keys described in the event.
|
|
139
139
|
*/
|
|
140
140
|
interface Fetcher {
|
|
141
141
|
/**
|
|
142
142
|
* Accept a configuration for an interventions endpoint, and set up a connection to subscribe for Interventions on any configured entities.
|
|
143
|
-
* @param config Endpoint/
|
|
143
|
+
* @param config Endpoint/attribute key configuration information.
|
|
144
144
|
*/
|
|
145
145
|
configure(config: SignalsInterventionConfiguration): void;
|
|
146
146
|
/**
|
|
147
|
-
* Called when a new Snowplow event has been observed or
|
|
147
|
+
* Called when a new Snowplow event has been observed or attribute key IDs provided. Attribute key IDs should be extracted and intervention subscription updated to accommodate new IDs if found.
|
|
148
148
|
* @param payload A Snowplow event payload observed.
|
|
149
|
-
* @param explicitEntities An explicit set of
|
|
149
|
+
* @param explicitEntities An explicit set of attribute key names/IDs to subscribe for.
|
|
150
150
|
*/
|
|
151
|
-
update(payload?: Payload, explicitEntities?: Record<
|
|
151
|
+
update(payload?: Payload, explicitEntities?: Record<AttributeKeyName, AttributeKeyId>): void;
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* `Handler`s are delivered Intervention instanced as they are received.
|
|
@@ -166,7 +166,7 @@ type Handler = (intervention: Intervention, tracker: BrowserTracker) => Promise<
|
|
|
166
166
|
declare function SignalsInterventionsPlugin({ fetcher, measurement, handlers }?: SignalsHandlerConfiguration): BrowserPlugin;
|
|
167
167
|
/**
|
|
168
168
|
* Configure the endpoint information for the plugin's `Fetcher` to subscribe to events from
|
|
169
|
-
* @param config Configuration about the endpoint and
|
|
169
|
+
* @param config Configuration about the endpoint and attribute key IDs/definitions to configure
|
|
170
170
|
* @param trackers List of tracker IDs that have activated the plugin to configure a `Fetcher` for
|
|
171
171
|
*/
|
|
172
172
|
declare function subscribeToInterventions(config: SignalsInterventionConfiguration, trackers?: TrackerId[]): void;
|
|
@@ -184,4 +184,4 @@ declare function addInterventionHandlers(handlers: Record<HandlerId, Handler>, t
|
|
|
184
184
|
declare function removeInterventionHandlers(handlerIds: OneOrMore<HandlerId>, trackers?: TrackerId[]): void;
|
|
185
185
|
|
|
186
186
|
export { SignalsInterventionsPlugin, addInterventionHandlers, removeInterventionHandlers, subscribeToInterventions };
|
|
187
|
-
export type {
|
|
187
|
+
export type { AttributeKeyId, AttributeKeyName, Fetcher, FetcherFactory, Handler, HandlerId, Intervention, JSONPointer, JSONPointerList, MeasurementEvents, MeasurementSettings, OneOrMore, SignalsHandlerConfiguration, SignalsInterventionConfiguration, TrackerId };
|
package/dist/index.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Snowplow Signals Interventions SDK v0.0
|
|
2
|
+
* Snowplow Signals Interventions SDK v0.1.0 (https://github.com/snowplow-incubator/signals-browser-plugin)
|
|
3
3
|
* Copyright 2025 Snowplow Analytics Ltd
|
|
4
4
|
* Licensed under BSD-3-Clause
|
|
5
5
|
*/
|
|
@@ -355,15 +355,15 @@ var derefJsonPointer = function (pointerString, obj) {
|
|
|
355
355
|
return cursor;
|
|
356
356
|
};
|
|
357
357
|
/**
|
|
358
|
-
* Given a list of rules to extract
|
|
359
|
-
* @param targets Map of
|
|
358
|
+
* Given a list of rules to extract attribute key IDs and a Snowplow event payload, return any extracted ID results.
|
|
359
|
+
* @param targets Map of attribute key names to rule definitions for how to find ID values
|
|
360
360
|
* @param pb Snowplow event
|
|
361
361
|
* @returns Resulting IDs extracted from the event
|
|
362
362
|
*/
|
|
363
|
-
function
|
|
363
|
+
function extractAttributeKeyValues(targets, pb) {
|
|
364
364
|
var extracted = {};
|
|
365
365
|
Object.entries(targets).forEach(function (_a) {
|
|
366
|
-
var
|
|
366
|
+
var attributeKeyName = _a[0], pointers = _a[1];
|
|
367
367
|
pointers = Array.isArray(pointers) ? pointers : [pointers];
|
|
368
368
|
for (var _i = 0, pointers_1 = pointers; _i < pointers_1.length; _i++) {
|
|
369
369
|
var pointer = pointers_1[_i];
|
|
@@ -372,7 +372,7 @@ function extractEntityValues(targets, pb) {
|
|
|
372
372
|
}
|
|
373
373
|
var candidateId = derefJsonPointer(pointer, pb);
|
|
374
374
|
if (candidateId != null) {
|
|
375
|
-
extracted[
|
|
375
|
+
extracted[attributeKeyName] = String(candidateId);
|
|
376
376
|
return;
|
|
377
377
|
}
|
|
378
378
|
}
|
|
@@ -381,26 +381,26 @@ function extractEntityValues(targets, pb) {
|
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
var DEFAULT_PULL_API_PATH = '/api/v1/interventions';
|
|
384
|
-
var
|
|
384
|
+
var DEFAULT_ATTRIBUTE_KEY_TARGETS = {
|
|
385
385
|
domain_userid: '/domain_userid',
|
|
386
386
|
domain_sessionid: '/domain_sessionid',
|
|
387
|
-
//pageview_id: '/co/com.snowplowanalytics.snowplow/web_page/id', // not a default
|
|
388
|
-
//tab_id: '/co/com.snowplowanalytics.snowplow/browser_context/tabId', // not a default
|
|
387
|
+
//pageview_id: '/co/com.snowplowanalytics.snowplow/web_page/id', // not a default attribute key seed
|
|
388
|
+
//tab_id: '/co/com.snowplowanalytics.snowplow/browser_context/tabId', // not a default attribute key seed
|
|
389
389
|
};
|
|
390
390
|
var DEFAULT_CONNECTION_TIMEOUT_MS = 2500;
|
|
391
391
|
/**
|
|
392
|
-
* Default `Fetcher` implementation; uses SSEs, auto updates based on observed
|
|
392
|
+
* Default `Fetcher` implementation; uses SSEs, auto updates based on observed attribute key IDs defined with JSON Pointers
|
|
393
393
|
*/
|
|
394
394
|
var InterventionFetcher = /** @class */ (function () {
|
|
395
395
|
function InterventionFetcher(tracker, dispatch) {
|
|
396
396
|
this.tracker = tracker;
|
|
397
397
|
this.dispatch = dispatch;
|
|
398
|
-
this.
|
|
398
|
+
this.attributeKeyValues = {};
|
|
399
399
|
this.aborter = new AbortController();
|
|
400
400
|
this.timeoutMs = DEFAULT_CONNECTION_TIMEOUT_MS;
|
|
401
401
|
this.newEndpoint = false;
|
|
402
402
|
this.currentParams = '';
|
|
403
|
-
this.
|
|
403
|
+
this.attributeKeySelectors = DEFAULT_ATTRIBUTE_KEY_TARGETS;
|
|
404
404
|
// reasonable defaults even without any events observed
|
|
405
405
|
var info = tracker.getDomainUserInfo();
|
|
406
406
|
this.update({
|
|
@@ -409,23 +409,23 @@ var InterventionFetcher = /** @class */ (function () {
|
|
|
409
409
|
});
|
|
410
410
|
}
|
|
411
411
|
InterventionFetcher.prototype.configure = function (_a) {
|
|
412
|
-
var endpoint = _a.endpoint, _b = _a.apiPath, apiPath = _b === void 0 ? DEFAULT_PULL_API_PATH : _b, _c = _a.
|
|
413
|
-
this.
|
|
412
|
+
var endpoint = _a.endpoint, _b = _a.apiPath, apiPath = _b === void 0 ? DEFAULT_PULL_API_PATH : _b, _c = _a.attributeKeyTargets, attributeKeyTargets = _c === void 0 ? DEFAULT_ATTRIBUTE_KEY_TARGETS : _c, _d = _a.attributeKeyIds, attributeKeyIds = _d === void 0 ? {} : _d, _e = _a.connectionTimeoutMs, connectionTimeoutMs = _e === void 0 ? DEFAULT_CONNECTION_TIMEOUT_MS : _e;
|
|
413
|
+
this.attributeKeySelectors = Object.assign({}, this.attributeKeySelectors, attributeKeyTargets);
|
|
414
414
|
this.timeoutMs = connectionTimeoutMs;
|
|
415
415
|
var prevEndpoint = this.endpoint;
|
|
416
416
|
this.endpoint = "".concat(/\/\//.test(endpoint) ? endpoint : 'https://' + endpoint).concat(apiPath);
|
|
417
417
|
this.newEndpoint = prevEndpoint != this.endpoint;
|
|
418
|
-
this.update(undefined,
|
|
418
|
+
this.update(undefined, attributeKeyIds);
|
|
419
419
|
};
|
|
420
|
-
InterventionFetcher.prototype.update = function (payload,
|
|
421
|
-
if (
|
|
420
|
+
InterventionFetcher.prototype.update = function (payload, explicitAttributeKeys) {
|
|
421
|
+
if (explicitAttributeKeys === void 0) { explicitAttributeKeys = {}; }
|
|
422
422
|
if (payload) {
|
|
423
|
-
Object.assign(this.
|
|
423
|
+
Object.assign(this.attributeKeyValues, extractAttributeKeyValues(this.attributeKeySelectors, payload));
|
|
424
424
|
}
|
|
425
|
-
Object.assign(this.
|
|
426
|
-
var newParams = new URLSearchParams(this.
|
|
425
|
+
Object.assign(this.attributeKeyValues, explicitAttributeKeys);
|
|
426
|
+
var newParams = new URLSearchParams(this.attributeKeyValues).toString();
|
|
427
427
|
if (this.endpoint && (newParams != this.currentParams || this.newEndpoint)) {
|
|
428
|
-
logger(LogLevel.DEBUG, this.tracker.id, '
|
|
428
|
+
logger(LogLevel.DEBUG, this.tracker.id, 'Attribute key IDs updated', this.attributeKeyValues);
|
|
429
429
|
this.currentParams = newParams;
|
|
430
430
|
this.requestInterventions();
|
|
431
431
|
}
|
|
@@ -538,8 +538,11 @@ var measure = function (settings, tracker, measurement, intervention, payload) {
|
|
|
538
538
|
intervention_id: intervention.intervention_id,
|
|
539
539
|
name: intervention.name,
|
|
540
540
|
version: intervention.version,
|
|
541
|
-
|
|
542
|
-
attributes: intervention.attributes
|
|
541
|
+
attributeKey: intervention.target_attribute_key,
|
|
542
|
+
attributes: Object.entries(intervention.attributes).map(function (_a) {
|
|
543
|
+
var attribute = _a[0], value = _a[1];
|
|
544
|
+
return ({ attribute: attribute, value: value });
|
|
545
|
+
}),
|
|
543
546
|
},
|
|
544
547
|
},
|
|
545
548
|
];
|
|
@@ -603,7 +606,7 @@ var dispatch = function (intervention, tracker) {
|
|
|
603
606
|
};
|
|
604
607
|
/**
|
|
605
608
|
* Configure the endpoint information for the plugin's `Fetcher` to subscribe to events from
|
|
606
|
-
* @param config Configuration about the endpoint and
|
|
609
|
+
* @param config Configuration about the endpoint and attribute key IDs/definitions to configure
|
|
607
610
|
* @param trackers List of tracker IDs that have activated the plugin to configure a `Fetcher` for
|
|
608
611
|
*/
|
|
609
612
|
function subscribeToInterventions(config, trackers) {
|