@snowplow/signals-browser-plugin 0.0.1 → 0.2.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/LICENSE +201 -29
- package/README.md +9 -9
- package/dist/index.module.d.ts +25 -25
- package/dist/index.module.js +32 -29
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +32 -29
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +3 -3
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +4 -3
package/dist/index.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Snowplow Signals Interventions SDK v0.0
|
|
2
|
+
* Snowplow Signals Interventions SDK v0.2.0 (https://github.com/snowplow-incubator/signals-browser-plugin)
|
|
3
3
|
* Copyright 2025 Snowplow Analytics Ltd
|
|
4
|
-
* Licensed under
|
|
4
|
+
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
(function (global, factory) {
|
|
@@ -652,15 +652,15 @@
|
|
|
652
652
|
return cursor;
|
|
653
653
|
};
|
|
654
654
|
/**
|
|
655
|
-
* Given a list of rules to extract
|
|
656
|
-
* @param targets Map of
|
|
655
|
+
* Given a list of rules to extract attribute key IDs and a Snowplow event payload, return any extracted ID results.
|
|
656
|
+
* @param targets Map of attribute key names to rule definitions for how to find ID values
|
|
657
657
|
* @param pb Snowplow event
|
|
658
658
|
* @returns Resulting IDs extracted from the event
|
|
659
659
|
*/
|
|
660
|
-
function
|
|
660
|
+
function extractAttributeKeyValues(targets, pb) {
|
|
661
661
|
var extracted = {};
|
|
662
662
|
Object.entries(targets).forEach(function (_a) {
|
|
663
|
-
var
|
|
663
|
+
var attributeKeyName = _a[0], pointers = _a[1];
|
|
664
664
|
pointers = Array.isArray(pointers) ? pointers : [pointers];
|
|
665
665
|
for (var _i = 0, pointers_1 = pointers; _i < pointers_1.length; _i++) {
|
|
666
666
|
var pointer = pointers_1[_i];
|
|
@@ -669,7 +669,7 @@
|
|
|
669
669
|
}
|
|
670
670
|
var candidateId = derefJsonPointer(pointer, pb);
|
|
671
671
|
if (candidateId != null) {
|
|
672
|
-
extracted[
|
|
672
|
+
extracted[attributeKeyName] = String(candidateId);
|
|
673
673
|
return;
|
|
674
674
|
}
|
|
675
675
|
}
|
|
@@ -678,26 +678,26 @@
|
|
|
678
678
|
}
|
|
679
679
|
|
|
680
680
|
var DEFAULT_PULL_API_PATH = '/api/v1/interventions';
|
|
681
|
-
var
|
|
681
|
+
var DEFAULT_ATTRIBUTE_KEY_TARGETS = {
|
|
682
682
|
domain_userid: '/domain_userid',
|
|
683
683
|
domain_sessionid: '/domain_sessionid',
|
|
684
|
-
//pageview_id: '/co/com.snowplowanalytics.snowplow/web_page/id', // not a default
|
|
685
|
-
//tab_id: '/co/com.snowplowanalytics.snowplow/browser_context/tabId', // not a default
|
|
684
|
+
//pageview_id: '/co/com.snowplowanalytics.snowplow/web_page/id', // not a default attribute key seed
|
|
685
|
+
//tab_id: '/co/com.snowplowanalytics.snowplow/browser_context/tabId', // not a default attribute key seed
|
|
686
686
|
};
|
|
687
687
|
var DEFAULT_CONNECTION_TIMEOUT_MS = 2500;
|
|
688
688
|
/**
|
|
689
|
-
* Default `Fetcher` implementation; uses SSEs, auto updates based on observed
|
|
689
|
+
* Default `Fetcher` implementation; uses SSEs, auto updates based on observed attribute key IDs defined with JSON Pointers
|
|
690
690
|
*/
|
|
691
691
|
var InterventionFetcher = /** @class */ (function () {
|
|
692
692
|
function InterventionFetcher(tracker, dispatch) {
|
|
693
693
|
this.tracker = tracker;
|
|
694
694
|
this.dispatch = dispatch;
|
|
695
|
-
this.
|
|
695
|
+
this.attributeKeyValues = {};
|
|
696
696
|
this.aborter = new AbortController();
|
|
697
697
|
this.timeoutMs = DEFAULT_CONNECTION_TIMEOUT_MS;
|
|
698
698
|
this.newEndpoint = false;
|
|
699
699
|
this.currentParams = '';
|
|
700
|
-
this.
|
|
700
|
+
this.attributeKeySelectors = DEFAULT_ATTRIBUTE_KEY_TARGETS;
|
|
701
701
|
// reasonable defaults even without any events observed
|
|
702
702
|
var info = tracker.getDomainUserInfo();
|
|
703
703
|
this.update({
|
|
@@ -706,23 +706,23 @@
|
|
|
706
706
|
});
|
|
707
707
|
}
|
|
708
708
|
InterventionFetcher.prototype.configure = function (_a) {
|
|
709
|
-
var endpoint = _a.endpoint, _b = _a.apiPath, apiPath = _b === void 0 ? DEFAULT_PULL_API_PATH : _b, _c = _a.
|
|
710
|
-
this.
|
|
709
|
+
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;
|
|
710
|
+
this.attributeKeySelectors = Object.assign({}, this.attributeKeySelectors, attributeKeyTargets);
|
|
711
711
|
this.timeoutMs = connectionTimeoutMs;
|
|
712
712
|
var prevEndpoint = this.endpoint;
|
|
713
713
|
this.endpoint = "".concat(/\/\//.test(endpoint) ? endpoint : 'https://' + endpoint).concat(apiPath);
|
|
714
714
|
this.newEndpoint = prevEndpoint != this.endpoint;
|
|
715
|
-
this.update(undefined,
|
|
715
|
+
this.update(undefined, attributeKeyIds);
|
|
716
716
|
};
|
|
717
|
-
InterventionFetcher.prototype.update = function (payload,
|
|
718
|
-
if (
|
|
717
|
+
InterventionFetcher.prototype.update = function (payload, explicitAttributeKeys) {
|
|
718
|
+
if (explicitAttributeKeys === void 0) { explicitAttributeKeys = {}; }
|
|
719
719
|
if (payload) {
|
|
720
|
-
Object.assign(this.
|
|
720
|
+
Object.assign(this.attributeKeyValues, extractAttributeKeyValues(this.attributeKeySelectors, payload));
|
|
721
721
|
}
|
|
722
|
-
Object.assign(this.
|
|
723
|
-
var newParams = new URLSearchParams(this.
|
|
722
|
+
Object.assign(this.attributeKeyValues, explicitAttributeKeys);
|
|
723
|
+
var newParams = new URLSearchParams(this.attributeKeyValues).toString();
|
|
724
724
|
if (this.endpoint && (newParams != this.currentParams || this.newEndpoint)) {
|
|
725
|
-
logger(LogLevel.DEBUG, this.tracker.id, '
|
|
725
|
+
logger(LogLevel.DEBUG, this.tracker.id, 'Attribute key IDs updated', this.attributeKeyValues);
|
|
726
726
|
this.currentParams = newParams;
|
|
727
727
|
this.requestInterventions();
|
|
728
728
|
}
|
|
@@ -788,11 +788,11 @@
|
|
|
788
788
|
var handlerRegistry = {}; // handlers can be added/removed for individual trackers
|
|
789
789
|
var measurementSettings = {}; // currently global and only specified per-plugin instance but may be required in future
|
|
790
790
|
/**
|
|
791
|
-
* Create an instance of the Signals
|
|
791
|
+
* Create an instance of the Signals plugin.
|
|
792
792
|
* @param configuration Configuration for the plugin
|
|
793
793
|
* @returns Configured plugin instance
|
|
794
794
|
*/
|
|
795
|
-
function
|
|
795
|
+
function SignalsPlugin(_a) {
|
|
796
796
|
var _b = _a === void 0 ? {
|
|
797
797
|
measurement: DEFAULT_MEASUREMENT_SETTINGS,
|
|
798
798
|
handlers: {},
|
|
@@ -812,7 +812,7 @@
|
|
|
812
812
|
}
|
|
813
813
|
},
|
|
814
814
|
logger: function (LOG) {
|
|
815
|
-
setLogger(
|
|
815
|
+
setLogger(SignalsPlugin.name, LOG);
|
|
816
816
|
},
|
|
817
817
|
};
|
|
818
818
|
}
|
|
@@ -835,8 +835,11 @@
|
|
|
835
835
|
intervention_id: intervention.intervention_id,
|
|
836
836
|
name: intervention.name,
|
|
837
837
|
version: intervention.version,
|
|
838
|
-
|
|
839
|
-
attributes: intervention.attributes
|
|
838
|
+
attributeKey: intervention.target_attribute_key,
|
|
839
|
+
attributes: Object.entries(intervention.attributes).map(function (_a) {
|
|
840
|
+
var attribute = _a[0], value = _a[1];
|
|
841
|
+
return ({ attribute: attribute, value: value });
|
|
842
|
+
}),
|
|
840
843
|
},
|
|
841
844
|
},
|
|
842
845
|
];
|
|
@@ -900,7 +903,7 @@
|
|
|
900
903
|
};
|
|
901
904
|
/**
|
|
902
905
|
* Configure the endpoint information for the plugin's `Fetcher` to subscribe to events from
|
|
903
|
-
* @param config Configuration about the endpoint and
|
|
906
|
+
* @param config Configuration about the endpoint and attribute key IDs/definitions to configure
|
|
904
907
|
* @param trackers List of tracker IDs that have activated the plugin to configure a `Fetcher` for
|
|
905
908
|
*/
|
|
906
909
|
function subscribeToInterventions(config, trackers) {
|
|
@@ -942,7 +945,7 @@
|
|
|
942
945
|
}
|
|
943
946
|
}
|
|
944
947
|
|
|
945
|
-
exports.
|
|
948
|
+
exports.SignalsPlugin = SignalsPlugin;
|
|
946
949
|
exports.addInterventionHandlers = addInterventionHandlers;
|
|
947
950
|
exports.removeInterventionHandlers = removeInterventionHandlers;
|
|
948
951
|
exports.subscribeToInterventions = subscribeToInterventions;
|