@magicpixel/rn-mp-client-sdk 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 +20 -0
- package/README.md +29 -0
- package/lib/commonjs/common/app-types.js +6 -0
- package/lib/commonjs/common/app-types.js.map +1 -0
- package/lib/commonjs/common/constants.js +51 -0
- package/lib/commonjs/common/constants.js.map +1 -0
- package/lib/commonjs/common/data-store.js +361 -0
- package/lib/commonjs/common/data-store.js.map +1 -0
- package/lib/commonjs/common/event-bus.js +42 -0
- package/lib/commonjs/common/event-bus.js.map +1 -0
- package/lib/commonjs/common/logger.js +30 -0
- package/lib/commonjs/common/logger.js.map +1 -0
- package/lib/commonjs/common/network-service.js +90 -0
- package/lib/commonjs/common/network-service.js.map +1 -0
- package/lib/commonjs/common/reporter.js +107 -0
- package/lib/commonjs/common/reporter.js.map +1 -0
- package/lib/commonjs/common/utils.js +276 -0
- package/lib/commonjs/common/utils.js.map +1 -0
- package/lib/commonjs/coverage/clover.xml +6 -0
- package/lib/commonjs/coverage/coverage-final.json +1 -0
- package/lib/commonjs/coverage/lcov-report/base.css +224 -0
- package/lib/commonjs/coverage/lcov-report/block-navigation.js +83 -0
- package/lib/commonjs/coverage/lcov-report/block-navigation.js.map +1 -0
- package/lib/commonjs/coverage/lcov-report/favicon.png +0 -0
- package/lib/commonjs/coverage/lcov-report/index.html +101 -0
- package/lib/commonjs/coverage/lcov-report/prettify.css +1 -0
- package/lib/commonjs/coverage/lcov-report/prettify.js +995 -0
- package/lib/commonjs/coverage/lcov-report/prettify.js.map +1 -0
- package/lib/commonjs/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/lib/commonjs/coverage/lcov-report/sorter.js +212 -0
- package/lib/commonjs/coverage/lcov-report/sorter.js.map +1 -0
- package/lib/commonjs/coverage/lcov.info +0 -0
- package/lib/commonjs/eedl/eedl.js +262 -0
- package/lib/commonjs/eedl/eedl.js.map +1 -0
- package/lib/commonjs/index.js +214 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/models/mp-client-sdk.js +33 -0
- package/lib/commonjs/models/mp-client-sdk.js.map +1 -0
- package/lib/commonjs/processors/data-element.processor.js +191 -0
- package/lib/commonjs/processors/data-element.processor.js.map +1 -0
- package/lib/commonjs/processors/qc.processor.js +111 -0
- package/lib/commonjs/processors/qc.processor.js.map +1 -0
- package/lib/commonjs/processors/tag.processor.js +432 -0
- package/lib/commonjs/processors/tag.processor.js.map +1 -0
- package/lib/commonjs/processors/trans-function.processor.js +91 -0
- package/lib/commonjs/processors/trans-function.processor.js.map +1 -0
- package/lib/commonjs/processors/visit-id.processor.js +172 -0
- package/lib/commonjs/processors/visit-id.processor.js.map +1 -0
- package/lib/module/common/app-types.js +2 -0
- package/lib/module/common/app-types.js.map +1 -0
- package/lib/module/common/constants.js +41 -0
- package/lib/module/common/constants.js.map +1 -0
- package/lib/module/common/data-store.js +346 -0
- package/lib/module/common/data-store.js.map +1 -0
- package/lib/module/common/event-bus.js +31 -0
- package/lib/module/common/event-bus.js.map +1 -0
- package/lib/module/common/logger.js +21 -0
- package/lib/module/common/logger.js.map +1 -0
- package/lib/module/common/network-service.js +73 -0
- package/lib/module/common/network-service.js.map +1 -0
- package/lib/module/common/reporter.js +88 -0
- package/lib/module/common/reporter.js.map +1 -0
- package/lib/module/common/utils.js +263 -0
- package/lib/module/common/utils.js.map +1 -0
- package/lib/module/coverage/clover.xml +6 -0
- package/lib/module/coverage/coverage-final.json +1 -0
- package/lib/module/coverage/lcov-report/base.css +224 -0
- package/lib/module/coverage/lcov-report/block-navigation.js +81 -0
- package/lib/module/coverage/lcov-report/block-navigation.js.map +1 -0
- package/lib/module/coverage/lcov-report/favicon.png +0 -0
- package/lib/module/coverage/lcov-report/index.html +101 -0
- package/lib/module/coverage/lcov-report/prettify.css +1 -0
- package/lib/module/coverage/lcov-report/prettify.js +993 -0
- package/lib/module/coverage/lcov-report/prettify.js.map +1 -0
- package/lib/module/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/lib/module/coverage/lcov-report/sorter.js +210 -0
- package/lib/module/coverage/lcov-report/sorter.js.map +1 -0
- package/lib/module/coverage/lcov.info +0 -0
- package/lib/module/eedl/eedl.js +246 -0
- package/lib/module/eedl/eedl.js.map +1 -0
- package/lib/module/index.js +176 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/models/mp-client-sdk.js +24 -0
- package/lib/module/models/mp-client-sdk.js.map +1 -0
- package/lib/module/processors/data-element.processor.js +176 -0
- package/lib/module/processors/data-element.processor.js.map +1 -0
- package/lib/module/processors/qc.processor.js +90 -0
- package/lib/module/processors/qc.processor.js.map +1 -0
- package/lib/module/processors/tag.processor.js +396 -0
- package/lib/module/processors/tag.processor.js.map +1 -0
- package/lib/module/processors/trans-function.processor.js +73 -0
- package/lib/module/processors/trans-function.processor.js.map +1 -0
- package/lib/module/processors/visit-id.processor.js +144 -0
- package/lib/module/processors/visit-id.processor.js.map +1 -0
- package/lib/typescript/common/app-types.d.ts +101 -0
- package/lib/typescript/common/constants.d.ts +21 -0
- package/lib/typescript/common/data-store.d.ts +81 -0
- package/lib/typescript/common/event-bus.d.ts +6 -0
- package/lib/typescript/common/logger.d.ts +5 -0
- package/lib/typescript/common/network-service.d.ts +8 -0
- package/lib/typescript/common/reporter.d.ts +12 -0
- package/lib/typescript/common/utils.d.ts +38 -0
- package/lib/typescript/eedl/eedl.d.ts +46 -0
- package/lib/typescript/index.d.ts +18 -0
- package/lib/typescript/models/mp-client-sdk.d.ts +157 -0
- package/lib/typescript/processors/data-element.processor.d.ts +12 -0
- package/lib/typescript/processors/qc.processor.d.ts +4 -0
- package/lib/typescript/processors/tag.processor.d.ts +27 -0
- package/lib/typescript/processors/trans-function.processor.d.ts +12 -0
- package/lib/typescript/processors/visit-id.processor.d.ts +7 -0
- package/package.json +170 -0
- package/src/common/app-types.ts +128 -0
- package/src/common/constants.ts +43 -0
- package/src/common/data-store.ts +333 -0
- package/src/common/event-bus.ts +35 -0
- package/src/common/logger.ts +19 -0
- package/src/common/network-service.ts +85 -0
- package/src/common/reporter.ts +110 -0
- package/src/common/utils.ts +281 -0
- package/src/coverage/clover.xml +6 -0
- package/src/coverage/coverage-final.json +1 -0
- package/src/coverage/lcov-report/base.css +224 -0
- package/src/coverage/lcov-report/block-navigation.js +87 -0
- package/src/coverage/lcov-report/favicon.png +0 -0
- package/src/coverage/lcov-report/index.html +101 -0
- package/src/coverage/lcov-report/prettify.css +1 -0
- package/src/coverage/lcov-report/prettify.js +2 -0
- package/src/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/src/coverage/lcov-report/sorter.js +196 -0
- package/src/coverage/lcov.info +0 -0
- package/src/eedl/eedl.ts +233 -0
- package/src/index.tsx +258 -0
- package/src/models/mp-client-sdk.ts +174 -0
- package/src/processors/data-element.processor.ts +249 -0
- package/src/processors/qc.processor.ts +115 -0
- package/src/processors/tag.processor.ts +527 -0
- package/src/processors/trans-function.processor.ts +85 -0
- package/src/processors/visit-id.processor.ts +164 -0
package/src/index.tsx
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { MpDataLayerHelper } from './eedl/eedl';
|
|
2
|
+
import type {
|
|
3
|
+
AppCustomerInfo,
|
|
4
|
+
AppPageLoad,
|
|
5
|
+
MapLike,
|
|
6
|
+
SdkInitOptions,
|
|
7
|
+
} from './common/app-types';
|
|
8
|
+
import { DataStore } from './common/data-store';
|
|
9
|
+
import { Logger } from './common/logger';
|
|
10
|
+
import { Reporter } from './common/reporter';
|
|
11
|
+
import { DataElementProcessor } from './processors/data-element.processor';
|
|
12
|
+
import { TagProcessor } from './processors/tag.processor';
|
|
13
|
+
import { Utils } from './common/utils';
|
|
14
|
+
import { QcProcessor } from './processors/qc.processor';
|
|
15
|
+
import { NetworkService } from './common/network-service';
|
|
16
|
+
import { EventBus } from './common/event-bus';
|
|
17
|
+
import { VisitIdProcessor } from './processors/visit-id.processor';
|
|
18
|
+
|
|
19
|
+
class MagicPixelImpl {
|
|
20
|
+
private static dl: MpDataLayerHelper;
|
|
21
|
+
private static customerInfo: AppCustomerInfo;
|
|
22
|
+
private static firstAppLaunch = true;
|
|
23
|
+
|
|
24
|
+
static async init(options: SdkInitOptions): Promise<void> {
|
|
25
|
+
this.dl = new MpDataLayerHelper('mpDlEvent', 'manual', 'page_load');
|
|
26
|
+
|
|
27
|
+
await NetworkService.refreshClientSdkJson(options);
|
|
28
|
+
|
|
29
|
+
if (!DataStore.isDataStoreReady()) {
|
|
30
|
+
throw new Error('MagicPixel SDK is not ready. No tags will be processed');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const sdk = DataStore.getClientSdk();
|
|
34
|
+
|
|
35
|
+
await VisitIdProcessor.init();
|
|
36
|
+
|
|
37
|
+
MagicPixelEventBus.on('mpDlEvent', async (evtName, payload) => {
|
|
38
|
+
console.log('mpDlEvent:: ', evtName, JSON.stringify(payload));
|
|
39
|
+
const eventName: string = payload.eventName;
|
|
40
|
+
const eventDataModel: MapLike = payload.model ?? {};
|
|
41
|
+
const eventId = eventDataModel['ev._id'];
|
|
42
|
+
|
|
43
|
+
Logger.logDbg('Tracking Event:: ', eventName, 'with id:: ', eventId);
|
|
44
|
+
|
|
45
|
+
if (sdk.mpDlE?.indexOf(eventName) > -1) {
|
|
46
|
+
// if this is something the tag manager is interested in - fire tag manager
|
|
47
|
+
DataStore.enQueueTMFire(
|
|
48
|
+
false,
|
|
49
|
+
`custom_event_${eventName}`,
|
|
50
|
+
eventName,
|
|
51
|
+
eventId,
|
|
52
|
+
eventDataModel
|
|
53
|
+
);
|
|
54
|
+
await this.checkAndFireTM();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static recordEvent(eventName: string, payload: MapLike): void {
|
|
60
|
+
if (this.customerInfo) {
|
|
61
|
+
const newPayload: MapLike = {
|
|
62
|
+
...payload,
|
|
63
|
+
...this.customerInfo,
|
|
64
|
+
};
|
|
65
|
+
this.dl.pushEvent(eventName, newPayload);
|
|
66
|
+
} else {
|
|
67
|
+
this.dl.pushEvent(eventName, payload);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static ready(): void {
|
|
72
|
+
this.dl.ready();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static async checkAndFireTM(): Promise<void> {
|
|
76
|
+
try {
|
|
77
|
+
if (!DataStore.isTagManagerProcessing()) {
|
|
78
|
+
const item = DataStore.deQueueTMFire();
|
|
79
|
+
if (item) {
|
|
80
|
+
Logger.logDbg(
|
|
81
|
+
'Executing TM For: ',
|
|
82
|
+
item.name,
|
|
83
|
+
', Event:: ',
|
|
84
|
+
item.dcrName,
|
|
85
|
+
', Event id:: ',
|
|
86
|
+
item.eventId,
|
|
87
|
+
'Payload:: ',
|
|
88
|
+
item.dcrPayload
|
|
89
|
+
);
|
|
90
|
+
await this.runTM(
|
|
91
|
+
item.sseOnly,
|
|
92
|
+
item.name,
|
|
93
|
+
item.dcrName,
|
|
94
|
+
item.eventId,
|
|
95
|
+
item.dcrPayload
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
Logger.logDbg(
|
|
100
|
+
'Tag Manager is processing or is not ready. This event will start after that'
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
Logger.logError('Error check and process tm', err);
|
|
105
|
+
Reporter.reportError('m:checkAndFireTM', err);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static async runTM(
|
|
110
|
+
sseOnly: boolean,
|
|
111
|
+
triggerName: string,
|
|
112
|
+
evtName: string,
|
|
113
|
+
evtId: string,
|
|
114
|
+
eventData?: Record<string, any>
|
|
115
|
+
): Promise<void> {
|
|
116
|
+
try {
|
|
117
|
+
Logger.logDbg(
|
|
118
|
+
'Running:: ',
|
|
119
|
+
sseOnly,
|
|
120
|
+
triggerName,
|
|
121
|
+
evtName,
|
|
122
|
+
evtId,
|
|
123
|
+
eventData
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// set tag manager in process status
|
|
127
|
+
DataStore.setTagManagerProcessing(true);
|
|
128
|
+
|
|
129
|
+
// process all the data elements and cache them for this run
|
|
130
|
+
await DataElementProcessor.processDataElements(
|
|
131
|
+
DataStore.getSdkDataElements(),
|
|
132
|
+
eventData
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const sdk = DataStore.getClientSdk();
|
|
136
|
+
|
|
137
|
+
const pcKey = DataStore.getSdkPcKey();
|
|
138
|
+
if (pcKey) {
|
|
139
|
+
const pcVal = DataStore.getDataElementValue(pcKey);
|
|
140
|
+
if (typeof pcVal !== 'undefined' && pcVal === true) {
|
|
141
|
+
Logger.logDbg('Set: PR Comp: ', true);
|
|
142
|
+
DataStore.setPrivacyCompliance(true);
|
|
143
|
+
} else {
|
|
144
|
+
Logger.logDbg('Set: PR Comp: ', false);
|
|
145
|
+
DataStore.setPrivacyCompliance(false);
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
Logger.logDbg('Set: PR Comp: ', false);
|
|
149
|
+
DataStore.setPrivacyCompliance(true);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (DataStore.getSdkPageLangKey()) {
|
|
153
|
+
DataStore.setDataElement(
|
|
154
|
+
'page_lang_key',
|
|
155
|
+
DataStore.getSdkPageLangKey()
|
|
156
|
+
);
|
|
157
|
+
DataStore.setPageLang(
|
|
158
|
+
DataStore.getDataElementValue('page_lang_key') as string
|
|
159
|
+
);
|
|
160
|
+
} else {
|
|
161
|
+
DataStore.setDataElement('page_lang_key', null);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
//set page_browser default data element with page_os because backend expects this
|
|
165
|
+
DataStore.setDataElement(
|
|
166
|
+
'page_browser',
|
|
167
|
+
DataStore.getOperatingSystem().toLowerCase()
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
Reporter.initReporter(
|
|
171
|
+
sdk.s.ev,
|
|
172
|
+
sdk.s.ev_id,
|
|
173
|
+
DataStore.getDeviceType(),
|
|
174
|
+
DataStore.getPageLang(),
|
|
175
|
+
DataStore.getDeviceOs(),
|
|
176
|
+
DataStore.getPageName(),
|
|
177
|
+
evtName,
|
|
178
|
+
evtId,
|
|
179
|
+
DataStore.getClientDownStream(),
|
|
180
|
+
DataStore.getCoreVersion(),
|
|
181
|
+
[]
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const validQCList = QcProcessor.processQc(
|
|
185
|
+
DataStore.getSdkQC(),
|
|
186
|
+
evtName,
|
|
187
|
+
evtId
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
if (validQCList?.length > 0) {
|
|
191
|
+
Logger.logDbg('Found Valid QCs to process', DataStore.getValidQcInfo());
|
|
192
|
+
|
|
193
|
+
TagProcessor.processTags(evtName, evtId)
|
|
194
|
+
.then(() => {
|
|
195
|
+
this._fireTM(sdk.s.ev, sdk.s.ev_id, evtName, evtId);
|
|
196
|
+
})
|
|
197
|
+
.catch((err) => {
|
|
198
|
+
Logger.logError('Error processing tag lists.', err);
|
|
199
|
+
Reporter.reportError('i::processTags', err);
|
|
200
|
+
this._fireTM(sdk.s.ev, sdk.s.ev_id, evtName, evtId);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
} catch (runTMErr) {
|
|
204
|
+
Logger.logError('Error in runTM', runTMErr);
|
|
205
|
+
Reporter.reportError('m::runTM', runTMErr);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static _fireTM(
|
|
210
|
+
envName: string,
|
|
211
|
+
envId: string,
|
|
212
|
+
evtName: string,
|
|
213
|
+
evtId: string
|
|
214
|
+
): void {
|
|
215
|
+
if (DataStore.hasOneSSTTag() && DataStore.shouldFireSstForEvent(evtName)) {
|
|
216
|
+
Reporter.postSST(
|
|
217
|
+
DataStore.getDataElements(),
|
|
218
|
+
envName,
|
|
219
|
+
envId,
|
|
220
|
+
DataStore.getSSTDownStream(),
|
|
221
|
+
evtName,
|
|
222
|
+
evtId
|
|
223
|
+
).catch((err: any) => {
|
|
224
|
+
Reporter.reportError('l::postSST', err);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
DataStore.setTagManagerProcessing(false);
|
|
229
|
+
Utils.sleep(250).then(async () => {
|
|
230
|
+
try {
|
|
231
|
+
await this.checkAndFireTM();
|
|
232
|
+
} catch (err) {
|
|
233
|
+
Reporter.reportError('i::runTM', err);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static setCustomerInfo(customerInfo: AppCustomerInfo): void {
|
|
239
|
+
this.customerInfo = customerInfo;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
static recordPageLoad(pageLoadInfo: AppPageLoad): void {
|
|
243
|
+
pageLoadInfo.is_entry = this.firstAppLaunch ? 1 : 0;
|
|
244
|
+
if (this.customerInfo) {
|
|
245
|
+
const newPayload: MapLike = {
|
|
246
|
+
...pageLoadInfo,
|
|
247
|
+
...this.customerInfo,
|
|
248
|
+
};
|
|
249
|
+
this.dl.pushEvent('page_load', newPayload);
|
|
250
|
+
} else {
|
|
251
|
+
this.dl.pushEvent('page_load', pageLoadInfo);
|
|
252
|
+
}
|
|
253
|
+
this.firstAppLaunch = false;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export const MagicPixelEventBus = EventBus;
|
|
258
|
+
export const MagicPixel = MagicPixelImpl;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { MapLike } from '../common/app-types';
|
|
2
|
+
|
|
3
|
+
export interface ClientSdkDeItem {
|
|
4
|
+
nm: string;
|
|
5
|
+
typ: string;
|
|
6
|
+
key?: string;
|
|
7
|
+
def?: any;
|
|
8
|
+
cl?: boolean;
|
|
9
|
+
lwcase?: boolean;
|
|
10
|
+
fn?: (deHelper: any, input: any) => any;
|
|
11
|
+
isAsync?: boolean;
|
|
12
|
+
fnTOut?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export enum ParamResourceEncodingType {
|
|
16
|
+
URL_ENC = 'URL_ENC',
|
|
17
|
+
BASE64 = 'BASE64',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export enum ParamResourceHashType {
|
|
21
|
+
SHA256 = 'SHA256',
|
|
22
|
+
SHA512 = 'SHA512',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export enum ParamResourceValSrc {
|
|
26
|
+
STATIC = 'STATIC',
|
|
27
|
+
DE = 'DE',
|
|
28
|
+
TRANS_FUNC = 'TRANS_FUNC',
|
|
29
|
+
CHILDREN = 'CHILDREN',
|
|
30
|
+
TG_JSON_PATH = 'TG_JSON_PATH',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface SdkParamEncodingTransformer {
|
|
34
|
+
nm: string;
|
|
35
|
+
eTyp: 'URL_ENC' | 'BASE64';
|
|
36
|
+
o?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SdkParamHashingTransformer {
|
|
40
|
+
nm: string;
|
|
41
|
+
hTyp: ParamResourceHashType;
|
|
42
|
+
o?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SdkParamIgnoreEmptyTransformer {
|
|
46
|
+
nm: string;
|
|
47
|
+
igEmpty: boolean;
|
|
48
|
+
o?: number; // order
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type TFType = (
|
|
52
|
+
| SdkParamHashingTransformer
|
|
53
|
+
| SdkParamEncodingTransformer
|
|
54
|
+
| SdkParamIgnoreEmptyTransformer
|
|
55
|
+
)[];
|
|
56
|
+
|
|
57
|
+
export interface ClientSdkParamItem {
|
|
58
|
+
id: string; // id
|
|
59
|
+
nm: string; // name
|
|
60
|
+
rqd?: boolean; // is mandatory
|
|
61
|
+
tf?: TFType; // transformation array
|
|
62
|
+
prLvl?: boolean; // is provider level attribute
|
|
63
|
+
pId?: string; // parent id
|
|
64
|
+
sv?: string; // static value
|
|
65
|
+
de?: string; // data element id
|
|
66
|
+
tfId?: string; // transformation function id
|
|
67
|
+
children?: ClientSdkParamItem[];
|
|
68
|
+
exclude_from_req_body?: boolean;
|
|
69
|
+
fKey: string; // flat key
|
|
70
|
+
val_src: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ClientSdkQcCondition {
|
|
74
|
+
param: string; // param name
|
|
75
|
+
i?: string[]; // include conditions
|
|
76
|
+
e?: string[]; // exclude conditions
|
|
77
|
+
i_ect: boolean; // is exact match for include
|
|
78
|
+
i_cs?: boolean; // is case-sensitive for include
|
|
79
|
+
e_ect?: boolean; // is exact match for exclude
|
|
80
|
+
e_cs?: boolean; // is case-sensitive for exclude
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ClientSdkPrItem {
|
|
84
|
+
nm: string;
|
|
85
|
+
url?: string; // base url
|
|
86
|
+
typ: string; // js or img provider
|
|
87
|
+
sTyp: string; // r or i sub type
|
|
88
|
+
rParams?: MapLike<ClientSdkParamItem>; // parameters
|
|
89
|
+
hrs?: MapLike<string>; // headers
|
|
90
|
+
ext?: string; // sdk extras joined into a string
|
|
91
|
+
src?: string; // src of the sdk
|
|
92
|
+
sync?: boolean; // should be loaded sync or async
|
|
93
|
+
pr: string; // whitelisted or black listed
|
|
94
|
+
chld?: boolean; // has at least one parameter whose val_src is CHILDREN
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface ClientSdkTfnItem {
|
|
98
|
+
nm: string; // name
|
|
99
|
+
fn: (input: any) => any; // js function in case this is a jsv data element
|
|
100
|
+
rParams: MapLike<ClientSdkParamItem>; // parameters
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface ClientSdkQcItem {
|
|
104
|
+
nm: string;
|
|
105
|
+
id: string;
|
|
106
|
+
c: ClientSdkQcCondition[];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface ClientSdkTagItem {
|
|
110
|
+
nm: string; // name
|
|
111
|
+
p: string; // provider id
|
|
112
|
+
url: string; // tag url
|
|
113
|
+
rParams?: MapLike<ClientSdkParamItem>;
|
|
114
|
+
st: number; // start time - in epoch seconds
|
|
115
|
+
ex: number; // expiry time - in epoch seconds
|
|
116
|
+
qc: string[];
|
|
117
|
+
img?: boolean; // is image tag
|
|
118
|
+
wrk?: boolean; // is web worker compatible
|
|
119
|
+
chld?: boolean; // has at least one parameter whose val_src is CHILDREN
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface ClientSdkSettingsItem {
|
|
123
|
+
dbg: boolean; // debug_enabled
|
|
124
|
+
err: boolean; // error_enabled
|
|
125
|
+
c_dom: string; // default cookie domain
|
|
126
|
+
v_dur: number; // visit duration
|
|
127
|
+
c_url: string; // collector_url
|
|
128
|
+
bare_c_url?: string; // bare collector url - transient variable
|
|
129
|
+
wh_idl?: string[]; // list of whitelisted idl events
|
|
130
|
+
wh_domains?: string[]; // list of white listed domains
|
|
131
|
+
c_url_lkp?: MapLike<{ v: string; ig: boolean; ect: boolean }>; // collector url look up
|
|
132
|
+
v_id: string; // vendor_id
|
|
133
|
+
p_id: string; // project_id
|
|
134
|
+
ev: string; // environment
|
|
135
|
+
ev_id: string; // environment id
|
|
136
|
+
dly: number; // trigger_delay
|
|
137
|
+
sst: boolean; // should enable server side. this will be set to true if there is atleast one sever side tag defined
|
|
138
|
+
idl: boolean; // should enable ID Link service. this will be set to true if the vendor has ID Link enabled
|
|
139
|
+
c_typ?: string; // the type of CSP, example nonce.
|
|
140
|
+
c_src?: string; // the source of CSP, example meta_tag for nonce type.
|
|
141
|
+
c_key?: string; // the data for CSP.
|
|
142
|
+
v: string; // core sdk version
|
|
143
|
+
bld_dt: string; // sdk build date and time from MP - this is not for the core sdk
|
|
144
|
+
p_view?: boolean; // should fire page info call or not to metrics
|
|
145
|
+
dws_c_t: 'j' | 'n'; // client side down stream (j = java, n = node)
|
|
146
|
+
dws_s_t: 'j' | 'n'; // server side down stream (j = java, n = node)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface BaseResourceParamType {
|
|
150
|
+
id: string; // id of param
|
|
151
|
+
nm: string; // name
|
|
152
|
+
o?: number; // order
|
|
153
|
+
pId?: string; // parent id
|
|
154
|
+
children?: BaseResourceParamType[];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface MpClientSdk {
|
|
158
|
+
langKey: string; // language data element id
|
|
159
|
+
pcKey: string; // privacy compliance key
|
|
160
|
+
cDomKey?: string; // collector domain tfn key
|
|
161
|
+
domWListKey?: string; // domain white list tfn function
|
|
162
|
+
d: MapLike<ClientSdkDeItem>; // data element map
|
|
163
|
+
qc?: ClientSdkQcItem[]; // qualification criteria
|
|
164
|
+
t?: MapLike<ClientSdkTagItem>; // tag map
|
|
165
|
+
p?: MapLike<ClientSdkPrItem>; // provider map
|
|
166
|
+
tfn?: MapLike<ClientSdkTfnItem>; // list of transformation functions
|
|
167
|
+
s: ClientSdkSettingsItem; // settings data item
|
|
168
|
+
dtmE: string[]; // list of dtm direct call events magic pixel should be interested in
|
|
169
|
+
ctmE: string[]; // list of custom javascript event magic pixel should be interested in
|
|
170
|
+
mpDlE: string[]; // list of MagicPixel data layer event magic pixel should be interested in
|
|
171
|
+
sseDtmE: string[]; // list of server side dtm events that we should trigger sst tag
|
|
172
|
+
sseCtmE: string[]; // list of custom window events that we should trigger sst tag
|
|
173
|
+
sseMpDlE: string[]; // list of mp dl events that should trigger the sst tag
|
|
174
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process data element of type url parameter
|
|
3
|
+
* @param de
|
|
4
|
+
*/
|
|
5
|
+
import { Utils } from '../common/utils';
|
|
6
|
+
import type { DeJsvHelper, MapLike } from '../common/app-types';
|
|
7
|
+
import type { ClientSdkDeItem } from '../models/mp-client-sdk';
|
|
8
|
+
import { DataStore } from '../common/data-store';
|
|
9
|
+
import { Logger } from '../common/logger';
|
|
10
|
+
|
|
11
|
+
const deJsvTimeOutPromise = (ms = 2000): Promise<any> => {
|
|
12
|
+
return new Promise((_resolve, reject) => {
|
|
13
|
+
const id = setTimeout(() => {
|
|
14
|
+
clearTimeout(id);
|
|
15
|
+
reject('Timed out in ' + ms + 'ms.');
|
|
16
|
+
}, ms);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const dElemProcessors: MapLike<
|
|
21
|
+
(
|
|
22
|
+
helper: DeJsvHelper,
|
|
23
|
+
elem: ClientSdkDeItem,
|
|
24
|
+
eventData?: Record<string, any>
|
|
25
|
+
) => any
|
|
26
|
+
> = {
|
|
27
|
+
mpdl: (
|
|
28
|
+
helper: DeJsvHelper,
|
|
29
|
+
elem: ClientSdkDeItem,
|
|
30
|
+
eventData?: Record<string, any>
|
|
31
|
+
): any => {
|
|
32
|
+
return processMpDl(helper, elem, eventData);
|
|
33
|
+
},
|
|
34
|
+
pg_os: (
|
|
35
|
+
_helper: DeJsvHelper,
|
|
36
|
+
_elem: ClientSdkDeItem,
|
|
37
|
+
_eventData?: Record<string, any>
|
|
38
|
+
): any => {
|
|
39
|
+
// already browser is in lower case, so no need to do it again
|
|
40
|
+
return DataStore.getOperatingSystem();
|
|
41
|
+
},
|
|
42
|
+
visit_id: (
|
|
43
|
+
_helper: DeJsvHelper,
|
|
44
|
+
_elem: ClientSdkDeItem,
|
|
45
|
+
_eventData?: Record<string, any>
|
|
46
|
+
): any => {
|
|
47
|
+
return DataStore.getVisitId();
|
|
48
|
+
},
|
|
49
|
+
pg_dtype: (_helper: DeJsvHelper, _elem: ClientSdkDeItem): any => {
|
|
50
|
+
return DataStore.getDeviceType();
|
|
51
|
+
},
|
|
52
|
+
pg_random: (
|
|
53
|
+
_helper: DeJsvHelper,
|
|
54
|
+
_elem: ClientSdkDeItem,
|
|
55
|
+
_eventData?: Record<string, any>
|
|
56
|
+
): any => {
|
|
57
|
+
return Utils.getUniqueID();
|
|
58
|
+
},
|
|
59
|
+
pg_empty_val: (
|
|
60
|
+
_helper: DeJsvHelper,
|
|
61
|
+
_elem: ClientSdkDeItem,
|
|
62
|
+
_eventData?: Record<string, any>
|
|
63
|
+
): any => {
|
|
64
|
+
return '';
|
|
65
|
+
},
|
|
66
|
+
mp_dvc_id: (
|
|
67
|
+
_helper: DeJsvHelper,
|
|
68
|
+
_elem: ClientSdkDeItem,
|
|
69
|
+
_eventData?: Record<string, any>
|
|
70
|
+
): any => {
|
|
71
|
+
return DataStore.getDeviceId();
|
|
72
|
+
},
|
|
73
|
+
mp_vis_id: (
|
|
74
|
+
_helper: DeJsvHelper,
|
|
75
|
+
_elem: ClientSdkDeItem,
|
|
76
|
+
_eventData?: Record<string, any>
|
|
77
|
+
): any => {
|
|
78
|
+
return DataStore.getMpId();
|
|
79
|
+
},
|
|
80
|
+
mp_org_id: (
|
|
81
|
+
_helper: DeJsvHelper,
|
|
82
|
+
_elem: ClientSdkDeItem,
|
|
83
|
+
_eventData?: Record<string, any>
|
|
84
|
+
): any => {
|
|
85
|
+
return DataStore.getOrgId();
|
|
86
|
+
},
|
|
87
|
+
mp_c_sdk_v: (
|
|
88
|
+
_helper: DeJsvHelper,
|
|
89
|
+
_elem: ClientSdkDeItem,
|
|
90
|
+
_eventData?: Record<string, any>
|
|
91
|
+
): any => {
|
|
92
|
+
return DataStore.getCoreVersion();
|
|
93
|
+
},
|
|
94
|
+
mp_c_sdk_env: (
|
|
95
|
+
_helper: DeJsvHelper,
|
|
96
|
+
_elem: ClientSdkDeItem,
|
|
97
|
+
_eventData?: Record<string, any>
|
|
98
|
+
): any => {
|
|
99
|
+
return DataStore.getMpEnv();
|
|
100
|
+
},
|
|
101
|
+
pg_mp_dl_evt_id: (
|
|
102
|
+
_helper: DeJsvHelper,
|
|
103
|
+
_elem: ClientSdkDeItem,
|
|
104
|
+
_eventData?: Record<string, any>
|
|
105
|
+
): any => {
|
|
106
|
+
_elem.key = 'ev._id';
|
|
107
|
+
return processMpDl(_helper, _elem, _eventData);
|
|
108
|
+
},
|
|
109
|
+
pg_mp_dl_evt_ts: (
|
|
110
|
+
_helper: DeJsvHelper,
|
|
111
|
+
_elem: ClientSdkDeItem,
|
|
112
|
+
_eventData?: Record<string, any>
|
|
113
|
+
): any => {
|
|
114
|
+
_elem.key = 'ev._tsMs';
|
|
115
|
+
return processMpDl(_helper, _elem, _eventData);
|
|
116
|
+
},
|
|
117
|
+
pg_mp_dl_evt_name: (
|
|
118
|
+
_helper: DeJsvHelper,
|
|
119
|
+
_elem: ClientSdkDeItem,
|
|
120
|
+
_eventData?: Record<string, any>
|
|
121
|
+
): any => {
|
|
122
|
+
_elem.key = 'ev._eventName';
|
|
123
|
+
return processMpDl(_helper, _elem, _eventData);
|
|
124
|
+
},
|
|
125
|
+
jsv: async (
|
|
126
|
+
helper: DeJsvHelper,
|
|
127
|
+
elem: ClientSdkDeItem,
|
|
128
|
+
_eventData?: Record<string, any>
|
|
129
|
+
): Promise<any> => {
|
|
130
|
+
try {
|
|
131
|
+
if (elem.fn) {
|
|
132
|
+
if (!elem.isAsync) {
|
|
133
|
+
return await elem.fn(helper, undefined);
|
|
134
|
+
} else {
|
|
135
|
+
return await Promise.race([
|
|
136
|
+
elem.fn(helper, undefined),
|
|
137
|
+
deJsvTimeOutPromise(elem.fnTOut || undefined),
|
|
138
|
+
]);
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
return elem.def || undefined;
|
|
142
|
+
}
|
|
143
|
+
} catch (err) {
|
|
144
|
+
Logger.logError(err);
|
|
145
|
+
return elem.def || undefined;
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
function generalCleanAndEscape(
|
|
151
|
+
helper: DeJsvHelper,
|
|
152
|
+
de: ClientSdkDeItem,
|
|
153
|
+
val: any
|
|
154
|
+
): string {
|
|
155
|
+
if (typeof de.fn === 'function') {
|
|
156
|
+
val = de.fn(helper, val);
|
|
157
|
+
return val;
|
|
158
|
+
} else {
|
|
159
|
+
if (typeof val === 'string') {
|
|
160
|
+
// clean
|
|
161
|
+
if (de.cl) {
|
|
162
|
+
val = val?.trim();
|
|
163
|
+
// see if it has a single quote or double quote, if so, escape it
|
|
164
|
+
if (val.indexOf(`'`) > -1) {
|
|
165
|
+
val = val.replace(/'/g, '');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (val.indexOf(`"`) > -1) {
|
|
169
|
+
val = val.replace(/"/g, '');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (de.lwcase) {
|
|
173
|
+
val = val?.toLowerCase();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return val;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function processMpDl(
|
|
181
|
+
helper: DeJsvHelper,
|
|
182
|
+
de: ClientSdkDeItem,
|
|
183
|
+
eventData?: Record<string, any>
|
|
184
|
+
): any {
|
|
185
|
+
try {
|
|
186
|
+
if (de.key) {
|
|
187
|
+
if (eventData && typeof eventData[de.key] !== 'undefined') {
|
|
188
|
+
return generalCleanAndEscape(helper, de, eventData[de.key]);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
} catch (err) {
|
|
192
|
+
Logger.logError('Error processing mp dl variable: ', err);
|
|
193
|
+
}
|
|
194
|
+
return generalCleanAndEscape(helper, de, de.def);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export class DataElementProcessor {
|
|
198
|
+
/**
|
|
199
|
+
* Process all the data elements at once, or if a set of keys are specified, processes only
|
|
200
|
+
* those keys and updates the dataElements object in global-fns file
|
|
201
|
+
* @param sdkDataElements
|
|
202
|
+
* @param eventData
|
|
203
|
+
* @param optDeKeys
|
|
204
|
+
*/
|
|
205
|
+
static async processDataElements(
|
|
206
|
+
sdkDataElements: MapLike<ClientSdkDeItem>,
|
|
207
|
+
eventData?: Record<string, any>,
|
|
208
|
+
optDeKeys?: string[]
|
|
209
|
+
): Promise<MapLike<any>> {
|
|
210
|
+
const de = DataStore.getDataElements();
|
|
211
|
+
const deKeys =
|
|
212
|
+
optDeKeys && optDeKeys.length > 0
|
|
213
|
+
? optDeKeys
|
|
214
|
+
: Object.keys(sdkDataElements);
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
const deHelper = DataStore.getDataElementHelpers();
|
|
218
|
+
for (const key of deKeys) {
|
|
219
|
+
try {
|
|
220
|
+
const deItem = sdkDataElements[key];
|
|
221
|
+
if (deItem) {
|
|
222
|
+
const invokeItem = dElemProcessors[deItem.typ];
|
|
223
|
+
if (dElemProcessors[deItem.typ]) {
|
|
224
|
+
Logger.logDbg('Processing data element: ', deItem.nm);
|
|
225
|
+
if (invokeItem) {
|
|
226
|
+
de[key] = await invokeItem(deHelper, deItem, eventData);
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
Logger.logError('No processor found for de typ: ', deItem.typ);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
} catch (err) {
|
|
233
|
+
Logger.logError(
|
|
234
|
+
'Error processing data element: ',
|
|
235
|
+
key,
|
|
236
|
+
' with error: ',
|
|
237
|
+
err
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
} catch (err) {
|
|
242
|
+
Logger.logError('Error processing data elements: ', err);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
DataStore.setDataElements(de);
|
|
246
|
+
Logger.logDbg('Data Elements: ', de);
|
|
247
|
+
return de;
|
|
248
|
+
}
|
|
249
|
+
}
|