@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.
@@ -25,21 +25,21 @@ type Intervention = {
25
25
  */
26
26
  version: number;
27
27
  /**
28
- * The complete or requested set of attributes for the Entity this intervention was triggered against an their values when it was triggered.
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 Entity that triggered this intervention or is intended to receive it.
32
+ * Information about the attribute key that triggered this intervention or is intended to receive it.
33
33
  */
34
- target_entity?: {
34
+ target_attribute_key?: {
35
35
  /**
36
- * The name/type of Entity that is the target/triggerer of this intervention.
36
+ * The name/type of attribute key that is the target/triggerer of this intervention.
37
37
  */
38
- name: EntityName;
38
+ name: AttributeKeyName;
39
39
  /**
40
- * The specific identifier for the instance of type `entityName` that is the target/triggerer of this intervention.
40
+ * The specific identifier for the instance of type `attributeKeyName` that is the target/triggerer of this intervention.
41
41
  */
42
- id?: EntityId;
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 entity type to request Interventions for. The name is paired with an EntityId as URL parameters in the request for Interventions.
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 EntityName = string;
60
+ type AttributeKeyName = string;
61
61
  /**
62
- * An identifier for a specific Entity instance.
62
+ * An identifier for a specific attribute key instance.
63
63
  */
64
- type EntityId = string;
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 entity 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.
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
- entityTargets?: Record<EntityName, JSONPointerList>;
88
+ attributeKeyTargets?: Record<AttributeKeyName, JSONPointerList>;
89
89
  /**
90
- * An explicit set of entity types and corresponding IDs to request interventions for.
90
+ * An explicit set of attribute key types and corresponding IDs to request interventions for.
91
91
  */
92
- entityIds?: Record<EntityName, EntityId>;
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 entity IDs are provided. It should update the connection so Interventions may be received for new entities described in the event.
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/entity configuration information.
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 entity IDs provided. Entity IDs should be extracted and intervention subscription updated to accommodate new IDs if found.
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 entity names/IDs to subscribe for.
149
+ * @param explicitEntities An explicit set of attribute key names/IDs to subscribe for.
150
150
  */
151
- update(payload?: Payload, explicitEntities?: Record<EntityName, EntityId>): void;
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 entity IDs/definitions to configure
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 { EntityId, EntityName, Fetcher, FetcherFactory, Handler, HandlerId, Intervention, JSONPointer, JSONPointerList, MeasurementEvents, MeasurementSettings, OneOrMore, SignalsHandlerConfiguration, SignalsInterventionConfiguration, TrackerId };
187
+ export type { AttributeKeyId, AttributeKeyName, Fetcher, FetcherFactory, Handler, HandlerId, Intervention, JSONPointer, JSONPointerList, MeasurementEvents, MeasurementSettings, OneOrMore, SignalsHandlerConfiguration, SignalsInterventionConfiguration, TrackerId };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Snowplow Signals Interventions SDK v0.0.1 (https://github.com/snowplow-incubator/signals-browser-plugin)
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 entity IDs and a Snowplow event payload, return any extracted ID results.
359
- * @param targets Map of entity names to rule definitions for how to find ID values
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 extractEntityValues(targets, pb) {
363
+ function extractAttributeKeyValues(targets, pb) {
364
364
  var extracted = {};
365
365
  Object.entries(targets).forEach(function (_a) {
366
- var entityName = _a[0], pointers = _a[1];
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[entityName] = String(candidateId);
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 DEFAULT_ENTITY_TARGETS = {
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 entity seed
388
- //tab_id: '/co/com.snowplowanalytics.snowplow/browser_context/tabId', // not a default entity seed
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 entity IDs defined with JSON Pointers
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.entityValues = {};
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.entitySelectors = DEFAULT_ENTITY_TARGETS;
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.entityTargets, entityTargets = _c === void 0 ? DEFAULT_ENTITY_TARGETS : _c, _d = _a.entityIds, entityIds = _d === void 0 ? {} : _d, _e = _a.connectionTimeoutMs, connectionTimeoutMs = _e === void 0 ? DEFAULT_CONNECTION_TIMEOUT_MS : _e;
413
- this.entitySelectors = Object.assign({}, this.entitySelectors, entityTargets);
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, entityIds);
418
+ this.update(undefined, attributeKeyIds);
419
419
  };
420
- InterventionFetcher.prototype.update = function (payload, explicitEntities) {
421
- if (explicitEntities === void 0) { explicitEntities = {}; }
420
+ InterventionFetcher.prototype.update = function (payload, explicitAttributeKeys) {
421
+ if (explicitAttributeKeys === void 0) { explicitAttributeKeys = {}; }
422
422
  if (payload) {
423
- Object.assign(this.entityValues, extractEntityValues(this.entitySelectors, payload));
423
+ Object.assign(this.attributeKeyValues, extractAttributeKeyValues(this.attributeKeySelectors, payload));
424
424
  }
425
- Object.assign(this.entityValues, explicitEntities);
426
- var newParams = new URLSearchParams(this.entityValues).toString();
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, 'Entity IDs updated', this.entityValues);
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
- entity: intervention.target_entity,
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 entity IDs/definitions to configure
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) {