|
@@ -121,6 +121,10 @@ class AnalyticsAdapter {
|
121
|
121
|
}
|
122
|
122
|
|
123
|
123
|
this.analyticsHandlers = new Set(handlers);
|
|
124
|
+ this.analyticsHandlers.forEach(
|
|
125
|
+ handler => {
|
|
126
|
+ handler.setUserProperties(this.permanentProperties);
|
|
127
|
+ });
|
124
|
128
|
|
125
|
129
|
// Note that we disable the cache even if the set of handlers is empty.
|
126
|
130
|
const cache = this.cache;
|
|
@@ -142,12 +146,14 @@ class AnalyticsAdapter {
|
142
|
146
|
* @param {Object} properties the properties to add
|
143
|
147
|
*/
|
144
|
148
|
addPermanentProperties(properties) {
|
145
|
|
- for (const property in properties) {
|
146
|
|
- if (properties.hasOwnProperty(property)) {
|
147
|
|
- this.permanentProperties[`permanent_${property}`]
|
148
|
|
- = properties[property];
|
149
|
|
- }
|
150
|
|
- }
|
|
149
|
+ this.permanentProperties = {
|
|
150
|
+ ...this.permanentProperties,
|
|
151
|
+ ...properties
|
|
152
|
+ };
|
|
153
|
+
|
|
154
|
+ this.analyticsHandlers.forEach(handler => {
|
|
155
|
+ handler.setUserProperties(this.permanentProperties);
|
|
156
|
+ });
|
151
|
157
|
}
|
152
|
158
|
|
153
|
159
|
/**
|
|
@@ -305,34 +311,15 @@ class AnalyticsAdapter {
|
305
|
311
|
if (this._maybeCacheEvent(event)) {
|
306
|
312
|
// The event was consumed by the cache.
|
307
|
313
|
} else {
|
308
|
|
- // We append the permanent properties at the time we send the event,
|
309
|
|
- // not at the time we receive it.
|
310
|
|
- this._appendPermanentProperties(event);
|
311
|
|
-
|
312
|
|
- for (const handler of this.analyticsHandlers) {
|
|
314
|
+ this.analyticsHandlers.forEach(handler => {
|
313
|
315
|
try {
|
314
|
316
|
handler.sendEvent(event);
|
315
|
317
|
} catch (e) {
|
316
|
318
|
logger.warn(`Error sending analytics event: ${e}`);
|
317
|
319
|
}
|
318
|
|
- }
|
319
|
|
- }
|
320
|
|
- }
|
321
|
|
-
|
322
|
|
- /**
|
323
|
|
- * Extends an event object with the configured permanent properties.
|
324
|
|
- * @param event the event to extend with permanent properties.
|
325
|
|
- * @private
|
326
|
|
- */
|
327
|
|
- _appendPermanentProperties(event) {
|
328
|
|
- if (!event.attributes) {
|
329
|
|
- event.attributes = {};
|
|
320
|
+ });
|
330
|
321
|
}
|
331
|
|
-
|
332
|
|
- event.attributes
|
333
|
|
- = Object.assign(event.attributes, this.permanentProperties);
|
334
|
322
|
}
|
335
|
|
-
|
336
|
323
|
}
|
337
|
324
|
|
338
|
325
|
export default new AnalyticsAdapter();
|