@mparticle/web-sdk 2.63.0 → 2.64.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/mparticle.common.js +58 -40
- package/dist/mparticle.esm.js +58 -40
- package/dist/mparticle.js +420 -222
- package/dist/types/src/forwarder-utils.d.ts +15 -0
- package/dist/types/src/helpers.d.ts +1 -1
- package/dist/types/src/sdkToEventsApiConverter.d.ts +2 -0
- package/dist/types/src/types.d.ts +3 -0
- package/dist/types/src/utils.d.ts +2 -1
- package/package.json +1 -1
- package/src/apiClient.ts +2 -2
- package/src/ecommerce.js +6 -13
- package/src/forwarder-utils.ts +260 -0
- package/src/forwarders.js +83 -195
- package/src/helpers.js +1 -148
- package/src/mockBatchCreator.ts +2 -1
- package/src/mp-instance.ts +2 -2
- package/src/persistence.js +4 -4
- package/src/sdkToEventsApiConverter.ts +55 -1
- package/src/serverModel.ts +2 -1
- package/src/store.ts +2 -3
- package/src/types.ts +134 -0
- package/src/utils.ts +135 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as EventsApi from '@mparticle/event-models';
|
|
2
|
+
import { IKitFilterSettings } from './configAPIClient';
|
|
3
|
+
type ForwarderFilterConfig = Pick<IKitFilterSettings, 'eventNameFilters' | 'eventTypeFilters' | 'screenNameFilters' | 'screenAttributeFilters' | 'attributeFilters' | 'userIdentityFilters' | 'filteringEventAttributeValue'>;
|
|
4
|
+
export declare function isBlockedByForwardingRule(messageType: number, attributes: Record<string, unknown> | null, forwarder: ForwarderFilterConfig): boolean;
|
|
5
|
+
export declare function isBlockedByEventFilter(messageType: number, hashedEventName: number, hashedEventType: number, forwarder: ForwarderFilterConfig): boolean;
|
|
6
|
+
export declare function filterEventAttributes(messageType: number, eventCategory: number, eventName: string, attributes: Record<string, unknown> | null, forwarder: ForwarderFilterConfig): Record<string, unknown> | null;
|
|
7
|
+
export declare function filterUserIdentities(userIdentities: Array<{
|
|
8
|
+
Type: number;
|
|
9
|
+
}> | undefined, filterList: number[]): Array<{
|
|
10
|
+
Type: number;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function isBatchEventAllowed(batchEvent: EventsApi.BaseEvent, forwarder: ForwarderFilterConfig): boolean;
|
|
13
|
+
export declare function filterBatchEventAttributes(batchEvent: EventsApi.BaseEvent, forwarder: ForwarderFilterConfig): void;
|
|
14
|
+
export declare function filterBatchIdentities(userIdentities: Record<string, unknown> | undefined, filterList: number[] | undefined): Record<string, unknown> | undefined;
|
|
15
|
+
export {};
|
|
@@ -5,7 +5,7 @@ export default class Helpers {
|
|
|
5
5
|
getFeatureFlag: (feature: any) => any;
|
|
6
6
|
invokeCallback: (callback: any, code: any, body: any, mParticleUser: any, previousMpid: any) => void;
|
|
7
7
|
invokeAliasCallback: (callback: any, code: any, message: any) => void;
|
|
8
|
-
extend:
|
|
8
|
+
extend: typeof utils.extend;
|
|
9
9
|
createServiceUrl: (secureServiceUrl: any, devToken: any) => string;
|
|
10
10
|
createXHR: (cb: any) => any;
|
|
11
11
|
filterUserIdentities: (userIdentitiesObject: any, filterList: any) => {
|
|
@@ -40,4 +40,6 @@ export declare function convertSDKLocation(sdkEventLocation: SDKGeoLocation): Ev
|
|
|
40
40
|
export declare function convertUserAttributeChangeEvent(sdkEvent: SDKEvent): EventsApi.UserAttributeChangeEvent | null;
|
|
41
41
|
export declare function convertUserIdentityChangeEvent(sdkEvent: SDKEvent): EventsApi.UserIdentityChangeEvent | null;
|
|
42
42
|
export declare function convertUserIdentityTypeToServerIdentityType(identityType: SDKIdentityTypeEnum): EventsApi.IdentityType;
|
|
43
|
+
export declare function getEventNameFromBatchEvent(batchEvent: EventsApi.BaseEvent): string;
|
|
44
|
+
export declare function getEventCategoryFromBatchEvent(batchEvent: EventsApi.BaseEvent): number;
|
|
43
45
|
export {};
|
|
@@ -74,6 +74,9 @@ export declare const PerformanceMarkType: {
|
|
|
74
74
|
JointSdkSelectPlacements: "mp:jointSdkSelectPlacements";
|
|
75
75
|
JointSdkRoktKitInit: "mp:jointSdkRoktKitInit";
|
|
76
76
|
};
|
|
77
|
+
export declare function getMessageTypeFromEventType(eventType: string): number;
|
|
78
|
+
export declare function getEventCategoryFromCustomEventType(customEventType: string): number;
|
|
79
|
+
export declare function getIdentityTypeFromBatchKey(key: string): number;
|
|
77
80
|
declare const _default: {
|
|
78
81
|
readonly MessageType: {
|
|
79
82
|
SessionStart: 1;
|
|
@@ -79,4 +79,5 @@ declare const obfuscateData: (value: any) => any;
|
|
|
79
79
|
* // Returns: { email: 'string' }
|
|
80
80
|
*/
|
|
81
81
|
declare const obfuscateDevData: (data: any, isDevelopmentMode?: boolean) => any;
|
|
82
|
-
|
|
82
|
+
declare function extend(...args: any[]): any;
|
|
83
|
+
export { createCookieString, revertCookieString, createCookieSyncUrl, valueof, AttributeValue, converted, decoded, obfuscateDevData, filterDictionaryWithHash, findKeyInObject, generateDeprecationMessage, generateHash, generateUniqueId, getRampNumber, inArray, isObject, isStringOrNumber, obfuscateData, parseConfig, parseNumber, parseSettingsString, parseStringOrNumber, replaceCommasWithPipes, replacePipesWithCommas, replaceApostrophesWithQuotes, replaceQuotesWithApostrophes, returnConvertedBoolean, toDataPlanSlug, isString, isNumber, isFunction, isDataPlanSlug, isEmpty, isValidAttributeValue, isValidCustomFlagProperty, mergeObjects, moveElementToEnd, queryStringParser, getCookies, getHref, replaceMPID, replaceAmpWithAmpersand, extend, };
|
package/package.json
CHANGED
package/src/apiClient.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Types from './types';
|
|
|
3
3
|
import { BatchUploader } from './batchUploader';
|
|
4
4
|
import { SDKEvent, SDKDataPlan } from './sdkRuntimeModels';
|
|
5
5
|
import KitBlocker from './kitBlocking';
|
|
6
|
-
import { Dictionary, isEmpty, parseNumber } from './utils';
|
|
6
|
+
import { Dictionary, isEmpty, parseNumber, extend } from './utils';
|
|
7
7
|
import { IUploadObject } from './serverModel';
|
|
8
8
|
import { MPForwarder } from './forwarders.interfaces';
|
|
9
9
|
import { IMParticleUser, ISDKUserAttributes } from './identity-user-interfaces';
|
|
@@ -122,7 +122,7 @@ export default function APIClient(
|
|
|
122
122
|
const defaultOptions = {
|
|
123
123
|
shouldUploadEvent: true,
|
|
124
124
|
};
|
|
125
|
-
const options =
|
|
125
|
+
const options = extend(defaultOptions, _options);
|
|
126
126
|
|
|
127
127
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
128
128
|
mpInstance._NativeSdkHelpers.sendToNative(
|
package/src/ecommerce.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Types from './types';
|
|
2
2
|
import Constants from './constants';
|
|
3
|
+
import { extend } from './utils';
|
|
3
4
|
|
|
4
5
|
var Messages = Constants.Messages;
|
|
5
6
|
|
|
@@ -378,13 +379,13 @@ export default function Ecommerce(mpInstance) {
|
|
|
378
379
|
commerceEvent.ProductImpressions.forEach(function(productImpression) {
|
|
379
380
|
if (productImpression.ProductList) {
|
|
380
381
|
productImpression.ProductList.forEach(function(product) {
|
|
381
|
-
|
|
382
|
+
let attributes = extend(
|
|
382
383
|
false,
|
|
383
384
|
{},
|
|
384
385
|
commerceEvent.EventAttributes
|
|
385
386
|
);
|
|
386
387
|
if (product.Attributes) {
|
|
387
|
-
for (
|
|
388
|
+
for (const attribute in product.Attributes) {
|
|
388
389
|
attributes[attribute] =
|
|
389
390
|
product.Attributes[attribute];
|
|
390
391
|
}
|
|
@@ -425,11 +426,7 @@ export default function Ecommerce(mpInstance) {
|
|
|
425
426
|
}
|
|
426
427
|
var promotions = commerceEvent.PromotionAction.PromotionList;
|
|
427
428
|
promotions.forEach(function(promotion) {
|
|
428
|
-
|
|
429
|
-
false,
|
|
430
|
-
{},
|
|
431
|
-
commerceEvent.EventAttributes
|
|
432
|
-
);
|
|
429
|
+
let attributes = extend(false, {}, commerceEvent.EventAttributes);
|
|
433
430
|
self.extractPromotionAttributes(attributes, promotion);
|
|
434
431
|
|
|
435
432
|
var appEvent = mpInstance._ServerModel.createEventObject({
|
|
@@ -459,11 +456,7 @@ export default function Ecommerce(mpInstance) {
|
|
|
459
456
|
commerceEvent.ProductAction.ProductActionType ===
|
|
460
457
|
Types.ProductActionType.Refund
|
|
461
458
|
) {
|
|
462
|
-
|
|
463
|
-
false,
|
|
464
|
-
{},
|
|
465
|
-
commerceEvent.EventAttributes
|
|
466
|
-
);
|
|
459
|
+
let attributes = extend(false, {}, commerceEvent.EventAttributes);
|
|
467
460
|
attributes['Product Count'] = commerceEvent.ProductAction
|
|
468
461
|
.ProductList
|
|
469
462
|
? commerceEvent.ProductAction.ProductList.length
|
|
@@ -498,7 +491,7 @@ export default function Ecommerce(mpInstance) {
|
|
|
498
491
|
}
|
|
499
492
|
|
|
500
493
|
products.forEach(function(product) {
|
|
501
|
-
|
|
494
|
+
let attributes = extend(
|
|
502
495
|
false,
|
|
503
496
|
commerceEvent.EventAttributes,
|
|
504
497
|
product.Attributes
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import Types, {
|
|
2
|
+
EventType,
|
|
3
|
+
getMessageTypeFromEventType,
|
|
4
|
+
getIdentityTypeFromBatchKey,
|
|
5
|
+
} from './types';
|
|
6
|
+
import { inArray, valueof } from './utils';
|
|
7
|
+
import KitFilterHelper from './kitFilterHelper';
|
|
8
|
+
import * as EventsApi from '@mparticle/event-models';
|
|
9
|
+
import { IKitFilterSettings } from './configAPIClient';
|
|
10
|
+
import {
|
|
11
|
+
getEventNameFromBatchEvent,
|
|
12
|
+
getEventCategoryFromBatchEvent,
|
|
13
|
+
} from './sdkToEventsApiConverter';
|
|
14
|
+
|
|
15
|
+
type ForwarderFilterConfig = Pick<
|
|
16
|
+
IKitFilterSettings,
|
|
17
|
+
| 'eventNameFilters'
|
|
18
|
+
| 'eventTypeFilters'
|
|
19
|
+
| 'screenNameFilters'
|
|
20
|
+
| 'screenAttributeFilters'
|
|
21
|
+
| 'attributeFilters'
|
|
22
|
+
| 'userIdentityFilters'
|
|
23
|
+
| 'filteringEventAttributeValue'
|
|
24
|
+
>;
|
|
25
|
+
|
|
26
|
+
const FORWARDING_RULE_MESSAGE_TYPES: number[] = [
|
|
27
|
+
Types.MessageType.PageEvent,
|
|
28
|
+
Types.MessageType.PageView,
|
|
29
|
+
Types.MessageType.Commerce,
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
function inFilteredList(
|
|
33
|
+
filterList: number[] | undefined,
|
|
34
|
+
hash: number
|
|
35
|
+
): boolean {
|
|
36
|
+
if (filterList && filterList.length) {
|
|
37
|
+
return inArray(filterList, hash);
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isBlockedByForwardingRule(
|
|
43
|
+
messageType: number,
|
|
44
|
+
attributes: Record<string, unknown> | null,
|
|
45
|
+
forwarder: ForwarderFilterConfig
|
|
46
|
+
): boolean {
|
|
47
|
+
if (
|
|
48
|
+
!FORWARDING_RULE_MESSAGE_TYPES.includes(messageType) ||
|
|
49
|
+
!forwarder.filteringEventAttributeValue ||
|
|
50
|
+
!forwarder.filteringEventAttributeValue.eventAttributeName ||
|
|
51
|
+
!forwarder.filteringEventAttributeValue.eventAttributeValue
|
|
52
|
+
) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let foundProp: { name: string; value: string } | null = null;
|
|
57
|
+
|
|
58
|
+
if (attributes) {
|
|
59
|
+
for (const prop in attributes) {
|
|
60
|
+
if (attributes.hasOwnProperty(prop)) {
|
|
61
|
+
const hashedName = KitFilterHelper.hashAttributeConditionalForwarding(
|
|
62
|
+
prop
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
if (
|
|
66
|
+
hashedName ===
|
|
67
|
+
forwarder.filteringEventAttributeValue.eventAttributeName
|
|
68
|
+
) {
|
|
69
|
+
foundProp = {
|
|
70
|
+
name: hashedName,
|
|
71
|
+
value: KitFilterHelper.hashAttributeConditionalForwarding(
|
|
72
|
+
attributes[prop] as string
|
|
73
|
+
),
|
|
74
|
+
};
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const isMatch =
|
|
82
|
+
foundProp !== null &&
|
|
83
|
+
foundProp.value ===
|
|
84
|
+
forwarder.filteringEventAttributeValue.eventAttributeValue;
|
|
85
|
+
|
|
86
|
+
const shouldInclude =
|
|
87
|
+
forwarder.filteringEventAttributeValue.includeOnMatch === true
|
|
88
|
+
? isMatch
|
|
89
|
+
: !isMatch;
|
|
90
|
+
|
|
91
|
+
return !shouldInclude;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function isBlockedByEventFilter(
|
|
95
|
+
messageType: number,
|
|
96
|
+
hashedEventName: number,
|
|
97
|
+
hashedEventType: number,
|
|
98
|
+
forwarder: ForwarderFilterConfig
|
|
99
|
+
): boolean {
|
|
100
|
+
if (
|
|
101
|
+
messageType === Types.MessageType.PageEvent &&
|
|
102
|
+
(inFilteredList(forwarder.eventNameFilters, hashedEventName) ||
|
|
103
|
+
inFilteredList(forwarder.eventTypeFilters, hashedEventType))
|
|
104
|
+
) {
|
|
105
|
+
return true;
|
|
106
|
+
} else if (
|
|
107
|
+
messageType === Types.MessageType.Commerce &&
|
|
108
|
+
inFilteredList(forwarder.eventTypeFilters, hashedEventType)
|
|
109
|
+
) {
|
|
110
|
+
return true;
|
|
111
|
+
} else if (
|
|
112
|
+
messageType === Types.MessageType.PageView &&
|
|
113
|
+
inFilteredList(forwarder.screenNameFilters, hashedEventName)
|
|
114
|
+
) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function filterEventAttributes(
|
|
121
|
+
messageType: number,
|
|
122
|
+
eventCategory: number,
|
|
123
|
+
eventName: string,
|
|
124
|
+
attributes: Record<string, unknown> | null,
|
|
125
|
+
forwarder: ForwarderFilterConfig
|
|
126
|
+
): Record<string, unknown> | null {
|
|
127
|
+
if (!attributes) {
|
|
128
|
+
return attributes;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let filterList: number[] | undefined;
|
|
132
|
+
if (messageType === Types.MessageType.PageEvent) {
|
|
133
|
+
filterList = forwarder.attributeFilters;
|
|
134
|
+
} else if (messageType === Types.MessageType.PageView) {
|
|
135
|
+
filterList = forwarder.screenAttributeFilters;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!filterList) {
|
|
139
|
+
return attributes;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const filtered: Record<string, unknown> = {};
|
|
143
|
+
for (const attrName in attributes) {
|
|
144
|
+
if (attributes.hasOwnProperty(attrName)) {
|
|
145
|
+
const hash = KitFilterHelper.hashEventAttributeKey(
|
|
146
|
+
eventCategory as valueof<typeof EventType>,
|
|
147
|
+
eventName,
|
|
148
|
+
attrName
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
if (!inArray(filterList, hash)) {
|
|
152
|
+
filtered[attrName] = attributes[attrName];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return filtered;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function filterUserIdentities(
|
|
160
|
+
userIdentities: Array<{ Type: number }> | undefined,
|
|
161
|
+
filterList: number[]
|
|
162
|
+
): Array<{ Type: number }> {
|
|
163
|
+
if (!userIdentities || !userIdentities.length) {
|
|
164
|
+
return userIdentities || [];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return userIdentities.filter(function(userIdentity) {
|
|
168
|
+
return !inArray(
|
|
169
|
+
filterList,
|
|
170
|
+
KitFilterHelper.hashUserIdentity(userIdentity.Type)
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function isBatchEventAllowed(
|
|
176
|
+
batchEvent: EventsApi.BaseEvent,
|
|
177
|
+
forwarder: ForwarderFilterConfig
|
|
178
|
+
): boolean {
|
|
179
|
+
if (!batchEvent || !(batchEvent as any).data) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const messageType = getMessageTypeFromEventType(
|
|
184
|
+
(batchEvent as any).event_type
|
|
185
|
+
);
|
|
186
|
+
const eventName = getEventNameFromBatchEvent(batchEvent);
|
|
187
|
+
const eventCategory = getEventCategoryFromBatchEvent(batchEvent);
|
|
188
|
+
|
|
189
|
+
if (
|
|
190
|
+
isBlockedByForwardingRule(
|
|
191
|
+
messageType,
|
|
192
|
+
(batchEvent as any).data.custom_attributes,
|
|
193
|
+
forwarder
|
|
194
|
+
)
|
|
195
|
+
) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const hashedEventName = KitFilterHelper.hashEventName(
|
|
200
|
+
eventName,
|
|
201
|
+
eventCategory as valueof<typeof EventType>
|
|
202
|
+
);
|
|
203
|
+
const hashedEventType = KitFilterHelper.hashEventType(
|
|
204
|
+
eventCategory as valueof<typeof EventType>
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
return !isBlockedByEventFilter(
|
|
208
|
+
messageType,
|
|
209
|
+
hashedEventName,
|
|
210
|
+
hashedEventType,
|
|
211
|
+
forwarder
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function filterBatchEventAttributes(
|
|
216
|
+
batchEvent: EventsApi.BaseEvent,
|
|
217
|
+
forwarder: ForwarderFilterConfig
|
|
218
|
+
): void {
|
|
219
|
+
if (!batchEvent || !(batchEvent as any).data) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const messageType = getMessageTypeFromEventType(
|
|
224
|
+
(batchEvent as any).event_type
|
|
225
|
+
);
|
|
226
|
+
const eventName = getEventNameFromBatchEvent(batchEvent);
|
|
227
|
+
const eventCategory = getEventCategoryFromBatchEvent(batchEvent);
|
|
228
|
+
|
|
229
|
+
(batchEvent as any).data.custom_attributes = filterEventAttributes(
|
|
230
|
+
messageType,
|
|
231
|
+
eventCategory,
|
|
232
|
+
eventName,
|
|
233
|
+
(batchEvent as any).data.custom_attributes,
|
|
234
|
+
forwarder
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function filterBatchIdentities(
|
|
239
|
+
userIdentities: Record<string, unknown> | undefined,
|
|
240
|
+
filterList: number[] | undefined
|
|
241
|
+
): Record<string, unknown> | undefined {
|
|
242
|
+
if (!userIdentities || !filterList) {
|
|
243
|
+
return userIdentities;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const filtered: Record<string, unknown> = {};
|
|
247
|
+
for (const key in userIdentities) {
|
|
248
|
+
if (userIdentities.hasOwnProperty(key)) {
|
|
249
|
+
const identityType = getIdentityTypeFromBatchKey(key);
|
|
250
|
+
|
|
251
|
+
if (
|
|
252
|
+
identityType === -1 ||
|
|
253
|
+
!inArray(filterList, identityType)
|
|
254
|
+
) {
|
|
255
|
+
filtered[key] = userIdentities[key];
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return filtered;
|
|
260
|
+
}
|