iidrak-analytics-react 1.2.4
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/README.md +170 -0
- package/index.d.ts +1 -0
- package/index.js +4 -0
- package/metastreamio/metastreamio.account.js +65 -0
- package/metastreamio/metastreamio.cart.js +192 -0
- package/metastreamio/metastreamio.constants.js +256 -0
- package/metastreamio/metastreamio.date.js +41 -0
- package/metastreamio/metastreamio.environment.js +406 -0
- package/metastreamio/metastreamio.interface.js +591 -0
- package/metastreamio/metastreamio.logger.js +150 -0
- package/metastreamio/metastreamio.network.js +313 -0
- package/metastreamio/metastreamio.provider.js +50 -0
- package/metastreamio/metastreamio.queue.js +68 -0
- package/metastreamio/metastreamio.recorder.js +157 -0
- package/metastreamio/metastreamio.session.js +150 -0
- package/metastreamio/metastreamio.user.js +79 -0
- package/metastreamio/metastreamio.userproperties.js +76 -0
- package/metastreamio/metastreamio.utility.js +206 -0
- package/metastreamio/models/constructor.app.js +24 -0
- package/metastreamio/models/constructor.config.js +33 -0
- package/metastreamio/models/constructor.user.js +30 -0
- package/metastreamio/models/event.account.balance.js +12 -0
- package/metastreamio/models/event.account.js +22 -0
- package/metastreamio/models/event.appinfo.js +28 -0
- package/metastreamio/models/event.appperformance.js +25 -0
- package/metastreamio/models/event.cart.js +19 -0
- package/metastreamio/models/event.cartitem.js +34 -0
- package/metastreamio/models/event.device.js +55 -0
- package/metastreamio/models/event.event.js +88 -0
- package/metastreamio/models/event.network.js +27 -0
- package/metastreamio/models/event.parameter.js +12 -0
- package/metastreamio/models/event.parameters.js +38 -0
- package/metastreamio/models/event.session.js +24 -0
- package/metastreamio/models/event.session.utm.js +37 -0
- package/metastreamio/models/event.userproperty.js +14 -0
- package/metastreamio/string.format.js +7 -0
- package/package.json +21 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { strf } from "./string.format.js";
|
|
4
|
+
|
|
5
|
+
strf();
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
*
|
|
9
|
+
* Date utilities class
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
class MetaStreamIODate {
|
|
14
|
+
constructor({ logger } = {}) {
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Generate a UTC timestamp at the time an event occurs
|
|
19
|
+
getEventTimestamp() {
|
|
20
|
+
var event_timestamp = new Date().getTime() * 1000;
|
|
21
|
+
return event_timestamp;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Get the current data
|
|
25
|
+
getEventDate() {
|
|
26
|
+
var date = new Date().toISOString().substr(0, 10);
|
|
27
|
+
return date;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Return the timezone offset of the device
|
|
31
|
+
getDeviceTimezoneOffset() {
|
|
32
|
+
const newDateNow = new Date();
|
|
33
|
+
return (newDateNow.getTimezoneOffset() * 60) / -1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
validateDatetime(dt) {
|
|
37
|
+
return new Date(dt).getTime() > 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { MetaStreamIODate };
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { strf } from "./string.format.js";
|
|
4
|
+
|
|
5
|
+
strf();
|
|
6
|
+
|
|
7
|
+
import DeviceInfo from "react-native-device-info";
|
|
8
|
+
|
|
9
|
+
import NetInfo from "@react-native-community/netinfo";
|
|
10
|
+
|
|
11
|
+
// import react native libraries
|
|
12
|
+
import { Dimensions } from "react-native";
|
|
13
|
+
|
|
14
|
+
// MetaStreamIO models
|
|
15
|
+
import { AppInfoModel } from "./models/event.appinfo.js";
|
|
16
|
+
import { AppPerformanceModel } from "./models/event.appperformance.js";
|
|
17
|
+
import { DeviceModel } from "./models/event.device.js";
|
|
18
|
+
import { NetworkInfoModel } from "./models/event.network.js";
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
*
|
|
22
|
+
* Environment class
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
class MetaStreamIOEnvironment {
|
|
27
|
+
constructor({ constants, logger, date, _enum } = {}) {
|
|
28
|
+
this.constant = constants;
|
|
29
|
+
this.date = date;
|
|
30
|
+
this.logger = logger;
|
|
31
|
+
this.app_info = new AppInfoModel();
|
|
32
|
+
this.app_performance = new AppPerformanceModel();
|
|
33
|
+
this.device = new DeviceModel();
|
|
34
|
+
this.network_info = new NetworkInfoModel();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
reset() {
|
|
38
|
+
this.app_info = new AppInfoModel();
|
|
39
|
+
this.app_performance = new AppPerformanceModel();
|
|
40
|
+
this.device = new DeviceModel();
|
|
41
|
+
this.network_info = new NetworkInfoModel();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async _getAppInfo() {
|
|
45
|
+
return await this.logAppInfo()
|
|
46
|
+
.then((appInfo) => {
|
|
47
|
+
return Promise.resolve(appInfo);
|
|
48
|
+
})
|
|
49
|
+
.catch((err) => {
|
|
50
|
+
return Promise.reject(err);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getAppInfo() {
|
|
55
|
+
return this.logAppInfo();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async logAppInfo() {
|
|
59
|
+
let app_id = null;
|
|
60
|
+
let first_installation_time = null;
|
|
61
|
+
let installation_id = null;
|
|
62
|
+
let install_referrer = null;
|
|
63
|
+
let last_update_time = null;
|
|
64
|
+
let version = null;
|
|
65
|
+
|
|
66
|
+
app_id = DeviceInfo.getBundleId() ? DeviceInfo.getBundleId() : null;
|
|
67
|
+
|
|
68
|
+
first_installation_time = await DeviceInfo.getFirstInstallTime()
|
|
69
|
+
.then((result) => {
|
|
70
|
+
if (this.date.validateDatetime(result)) {
|
|
71
|
+
return result;
|
|
72
|
+
} else {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
.catch((err) => {
|
|
77
|
+
this.logger.warn(
|
|
78
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
79
|
+
err
|
|
80
|
+
);
|
|
81
|
+
return null;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
installation_id = "deprecated"; // Constants.installationId;
|
|
85
|
+
|
|
86
|
+
install_referrer = await DeviceInfo.getInstallReferrer()
|
|
87
|
+
.then((result) => {
|
|
88
|
+
return result;
|
|
89
|
+
})
|
|
90
|
+
.catch((err) => {
|
|
91
|
+
this.logger.warn(
|
|
92
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
93
|
+
err
|
|
94
|
+
);
|
|
95
|
+
return null;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
last_update_time = await DeviceInfo.getLastUpdateTime()
|
|
99
|
+
.then((result) => {
|
|
100
|
+
if (this.date.validateDatetime(result)) {
|
|
101
|
+
return result;
|
|
102
|
+
} else {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
.catch((err) => {
|
|
107
|
+
this.logger.warn(
|
|
108
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
109
|
+
err
|
|
110
|
+
);
|
|
111
|
+
return null;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
version = DeviceInfo.getVersion() ? DeviceInfo.getVersion() : null;
|
|
115
|
+
|
|
116
|
+
this.app_info = new AppInfoModel({
|
|
117
|
+
first_installation_time: first_installation_time,
|
|
118
|
+
id: app_id,
|
|
119
|
+
installation_id: installation_id,
|
|
120
|
+
install_referrer: install_referrer,
|
|
121
|
+
last_update_time: last_update_time,
|
|
122
|
+
version: version,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
this.logger.log(
|
|
126
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
127
|
+
this.constant.MetaStreamIO_Environment_AppInfo.format(
|
|
128
|
+
JSON.stringify(this.app_info)
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
return this.app_info.json();
|
|
133
|
+
|
|
134
|
+
// return Promise.resolve(this.app_info.json());
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async getAppPerformance() {
|
|
138
|
+
return await this.logAppPerformance();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async logAppPerformance() {
|
|
142
|
+
let battery_info, battery_level, battery_low_power_mode, battery_state;
|
|
143
|
+
|
|
144
|
+
battery_info = {};
|
|
145
|
+
|
|
146
|
+
DeviceInfo.getPowerState()
|
|
147
|
+
.then((state) => {
|
|
148
|
+
battery_info.battery_level = state.batteryLevel;
|
|
149
|
+
battery_info.battery_state = state.batteryState;
|
|
150
|
+
battery_info.battery_low_power_mode = state.lowPowerMode;
|
|
151
|
+
})
|
|
152
|
+
.catch((err) => {
|
|
153
|
+
this.logger.warn(
|
|
154
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
155
|
+
err
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
this.app_performance = new AppPerformanceModel({
|
|
160
|
+
battery_low_power_mode: battery_low_power_mode,
|
|
161
|
+
battery_percentage: battery_level,
|
|
162
|
+
battery_state: battery_state,
|
|
163
|
+
data_down_kb: 0,
|
|
164
|
+
data_up_kb: 0,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
this.logger.log(
|
|
168
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
169
|
+
this.constant.MetaStreamIO_Environment_AppPerformance.format(
|
|
170
|
+
JSON.stringify(this.app_performance)
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
return Promise.resolve(this.app_performance.json());
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async getDevice() {
|
|
178
|
+
return await this.logDevice()
|
|
179
|
+
.then((device) => {
|
|
180
|
+
return Promise.resolve(device);
|
|
181
|
+
})
|
|
182
|
+
.catch((err) => {
|
|
183
|
+
return Promise.reject(err);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async logDevice() {
|
|
188
|
+
let brand,
|
|
189
|
+
device_type,
|
|
190
|
+
model,
|
|
191
|
+
operating_system,
|
|
192
|
+
operating_system_version,
|
|
193
|
+
pin_or_fingerprint_set,
|
|
194
|
+
screen_width,
|
|
195
|
+
screen_height,
|
|
196
|
+
storage_total,
|
|
197
|
+
storage_free,
|
|
198
|
+
supported_architectures,
|
|
199
|
+
timezone_offset_sec,
|
|
200
|
+
total_memory,
|
|
201
|
+
unique_device_id,
|
|
202
|
+
used_memory;
|
|
203
|
+
|
|
204
|
+
brand = await DeviceInfo.getBrand();
|
|
205
|
+
|
|
206
|
+
device_type = await DeviceInfo.getDeviceType();
|
|
207
|
+
|
|
208
|
+
model = DeviceInfo.getModel();
|
|
209
|
+
|
|
210
|
+
operating_system = DeviceInfo.getSystemName();
|
|
211
|
+
|
|
212
|
+
operating_system_version = DeviceInfo.getSystemVersion();
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
screen_height = Math.round(Dimensions.get("window").height);
|
|
216
|
+
} catch {
|
|
217
|
+
screen_height = null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
screen_width = Math.round(Dimensions.get("window").width);
|
|
222
|
+
} catch {
|
|
223
|
+
screen_width = null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
storage_free = await DeviceInfo.getFreeDiskStorage()
|
|
227
|
+
.then((result) => {
|
|
228
|
+
return result;
|
|
229
|
+
})
|
|
230
|
+
.catch((err) => {
|
|
231
|
+
this.logger.warn(
|
|
232
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
233
|
+
err
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
storage_total = await DeviceInfo.getTotalDiskCapacity()
|
|
238
|
+
.then((result) => {
|
|
239
|
+
return result;
|
|
240
|
+
})
|
|
241
|
+
.catch((err) => {
|
|
242
|
+
this.logger.warn(
|
|
243
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
244
|
+
err
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
supported_architectures = await DeviceInfo.supportedAbis()
|
|
249
|
+
.then((result) => {
|
|
250
|
+
return result.join(",");
|
|
251
|
+
})
|
|
252
|
+
.catch((err) => {
|
|
253
|
+
this.logger.warn(
|
|
254
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
255
|
+
err
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
total_memory = await DeviceInfo.getTotalMemory()
|
|
260
|
+
.then((result) => {
|
|
261
|
+
return result;
|
|
262
|
+
})
|
|
263
|
+
.catch((err) => {
|
|
264
|
+
this.logger.warn(
|
|
265
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
266
|
+
err
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
unique_device_id = DeviceInfo.getUniqueId()
|
|
271
|
+
? DeviceInfo.getUniqueId()
|
|
272
|
+
: null;
|
|
273
|
+
|
|
274
|
+
used_memory = await DeviceInfo.getUsedMemory()
|
|
275
|
+
.then((result) => {
|
|
276
|
+
return result;
|
|
277
|
+
})
|
|
278
|
+
.catch((err) => {
|
|
279
|
+
this.logger.warn(
|
|
280
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
281
|
+
err
|
|
282
|
+
);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
try {
|
|
286
|
+
timezone_offset_sec = this.date.getDeviceTimezoneOffset();
|
|
287
|
+
} catch {
|
|
288
|
+
timezone_offset_sec = null;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
pin_or_fingerprint_set = await DeviceInfo.isPinOrFingerprintSet()
|
|
292
|
+
.then((result) => {
|
|
293
|
+
return result;
|
|
294
|
+
})
|
|
295
|
+
.catch((err) => {
|
|
296
|
+
this.logger.warn(
|
|
297
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
298
|
+
err
|
|
299
|
+
);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
this.device = new DeviceModel({
|
|
303
|
+
brand: brand,
|
|
304
|
+
device_type: device_type,
|
|
305
|
+
model: model,
|
|
306
|
+
operating_system: operating_system,
|
|
307
|
+
operating_system_version: operating_system_version,
|
|
308
|
+
pin_or_fingerprint_set: pin_or_fingerprint_set,
|
|
309
|
+
screen_height: screen_height,
|
|
310
|
+
screen_width: screen_width,
|
|
311
|
+
storage_free: storage_free,
|
|
312
|
+
storage_total: storage_total,
|
|
313
|
+
supported_architectures: supported_architectures,
|
|
314
|
+
timezone_offset_sec: timezone_offset_sec,
|
|
315
|
+
total_memory: total_memory,
|
|
316
|
+
unique_device_id: unique_device_id,
|
|
317
|
+
used_memory: used_memory,
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
this.logger.log(
|
|
321
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
322
|
+
this.constant.MetaStreamIO_Environment_Device.format(
|
|
323
|
+
JSON.stringify(this.device)
|
|
324
|
+
)
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
return Promise.resolve(this.device.json());
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
async getNetworkInfo() {
|
|
331
|
+
return await this.logNetworkInfo()
|
|
332
|
+
.then((networkInfo) => {
|
|
333
|
+
return Promise.resolve(networkInfo);
|
|
334
|
+
})
|
|
335
|
+
.catch((err) => {
|
|
336
|
+
return Promise.reject(err);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async logNetworkInfo() {
|
|
341
|
+
let carrier,
|
|
342
|
+
carrier_iso_country_code,
|
|
343
|
+
cellular_generation,
|
|
344
|
+
mobile_country_code,
|
|
345
|
+
mobile_network_code,
|
|
346
|
+
network_state_type,
|
|
347
|
+
net_info;
|
|
348
|
+
|
|
349
|
+
carrier = await DeviceInfo.getCarrier()
|
|
350
|
+
.then((result) => {
|
|
351
|
+
return result;
|
|
352
|
+
})
|
|
353
|
+
.catch((err) => {
|
|
354
|
+
this.logger.warn(
|
|
355
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
356
|
+
err
|
|
357
|
+
);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
net_info = await NetInfo.fetch()
|
|
361
|
+
.then((state) => {
|
|
362
|
+
return {
|
|
363
|
+
connection_type: state.type,
|
|
364
|
+
connection_active: state.isConnected,
|
|
365
|
+
cellular_generation:
|
|
366
|
+
state.type === "cellular" ? state.details.cellularGeneration : null,
|
|
367
|
+
};
|
|
368
|
+
})
|
|
369
|
+
.catch((err) => {
|
|
370
|
+
this.logger.warn(
|
|
371
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
372
|
+
err
|
|
373
|
+
);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
carrier_iso_country_code = null;
|
|
377
|
+
|
|
378
|
+
cellular_generation = net_info.cellular_generation;
|
|
379
|
+
|
|
380
|
+
mobile_country_code = null;
|
|
381
|
+
|
|
382
|
+
mobile_network_code = null;
|
|
383
|
+
|
|
384
|
+
network_state_type = net_info.connection_type;
|
|
385
|
+
|
|
386
|
+
this.logger.log(
|
|
387
|
+
this.constant.MetaStreamIO_Logger_Category_Environment,
|
|
388
|
+
this.constant.MetaStreamIO_Environment_Network.format(
|
|
389
|
+
JSON.stringify(this.network_info)
|
|
390
|
+
)
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
this.network_info = new NetworkInfoModel({
|
|
394
|
+
carrier: carrier,
|
|
395
|
+
carrier_iso_country_code: carrier_iso_country_code,
|
|
396
|
+
cellular_generation: cellular_generation,
|
|
397
|
+
mobile_country_code: mobile_country_code,
|
|
398
|
+
mobile_network_code: mobile_network_code,
|
|
399
|
+
network_state_type: network_state_type,
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
return Promise.resolve(this.network_info.json());
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export { MetaStreamIOEnvironment };
|