@magicpixel/rn-mp-client-sdk 0.2.0 → 0.4.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.
Files changed (35) hide show
  1. package/lib/commonjs/common/constants.js +2 -0
  2. package/lib/commonjs/common/constants.js.map +1 -1
  3. package/lib/commonjs/common/data-store.js +3 -7
  4. package/lib/commonjs/common/data-store.js.map +1 -1
  5. package/lib/commonjs/common/network-service.js +1 -3
  6. package/lib/commonjs/common/network-service.js.map +1 -1
  7. package/lib/commonjs/common/utils.js +12 -0
  8. package/lib/commonjs/common/utils.js.map +1 -1
  9. package/lib/commonjs/index.js +32 -4
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/processors/visit-id.processor.js +17 -0
  12. package/lib/commonjs/processors/visit-id.processor.js.map +1 -1
  13. package/lib/module/common/constants.js +2 -0
  14. package/lib/module/common/constants.js.map +1 -1
  15. package/lib/module/common/data-store.js +3 -7
  16. package/lib/module/common/data-store.js.map +1 -1
  17. package/lib/module/common/network-service.js +1 -2
  18. package/lib/module/common/network-service.js.map +1 -1
  19. package/lib/module/common/utils.js +10 -0
  20. package/lib/module/common/utils.js.map +1 -1
  21. package/lib/module/index.js +31 -4
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/processors/visit-id.processor.js +17 -0
  24. package/lib/module/processors/visit-id.processor.js.map +1 -1
  25. package/lib/typescript/common/constants.d.ts +1 -0
  26. package/lib/typescript/common/utils.d.ts +3 -0
  27. package/lib/typescript/index.d.ts +3 -0
  28. package/lib/typescript/processors/visit-id.processor.d.ts +1 -0
  29. package/package.json +1 -4
  30. package/src/common/constants.ts +1 -0
  31. package/src/common/data-store.ts +3 -6
  32. package/src/common/network-service.ts +1 -2
  33. package/src/common/utils.ts +13 -0
  34. package/src/index.tsx +29 -2
  35. package/src/processors/visit-id.processor.ts +16 -0
@@ -8,12 +8,25 @@ import type {
8
8
  import type { MapLike } from './app-types';
9
9
  import { unflatten } from 'flat';
10
10
  import { EventBus } from './event-bus';
11
+ import { Dimensions, ScaledSize } from 'react-native';
11
12
 
12
13
  export class Utils {
13
14
  static triggerEvent(eventName: string, payload: any): void {
14
15
  EventBus.triggerEvent(eventName, payload);
15
16
  }
16
17
 
18
+ static calculateMsp(dim: ScaledSize, limit: number): boolean {
19
+ return dim.scale * dim.width >= limit || dim.scale * dim.height >= limit;
20
+ }
21
+
22
+ static isTablet(): boolean {
23
+ const dim = Dimensions.get('screen');
24
+ return (
25
+ (dim.scale < 2 && this.calculateMsp(dim, 1000)) ||
26
+ (dim.scale >= 2 && this.calculateMsp(dim, 1900))
27
+ );
28
+ }
29
+
17
30
  static sleep(delay = 1000): Promise<void> {
18
31
  return new Promise((resolve: (val?: any) => void) => {
19
32
  setTimeout(() => {
package/src/index.tsx CHANGED
@@ -19,6 +19,7 @@ import { VisitIdProcessor } from './processors/visit-id.processor';
19
19
  class MagicPixelImpl {
20
20
  private static dl: MpDataLayerHelper;
21
21
  private static customerInfo: AppCustomerInfo;
22
+ private static customerIdentifiers: MapLike = {};
22
23
  private static firstAppLaunch = true;
23
24
 
24
25
  static async init(options: SdkInitOptions): Promise<void> {
@@ -34,6 +35,14 @@ class MagicPixelImpl {
34
35
 
35
36
  await VisitIdProcessor.init();
36
37
 
38
+ const fbp = await VisitIdProcessor.getFacebookFBP();
39
+ if (fbp) {
40
+ Logger.logDbg('Setting facebook client id', fbp);
41
+ this.setFacebookClientId(fbp);
42
+ } else {
43
+ Logger.logDbg('No facebook client id found. not setting');
44
+ }
45
+
37
46
  MagicPixelEventBus.on('mpDlEvent', async (evtName, payload) => {
38
47
  console.log('mpDlEvent:: ', evtName, JSON.stringify(payload));
39
48
  const eventName: string = payload.eventName;
@@ -61,10 +70,15 @@ class MagicPixelImpl {
61
70
  const newPayload: MapLike = {
62
71
  ...payload,
63
72
  ...this.customerInfo,
73
+ ...(this.customerIdentifiers ?? {}),
64
74
  };
65
75
  this.dl.pushEvent(eventName, newPayload);
66
76
  } else {
67
- this.dl.pushEvent(eventName, payload);
77
+ const newPayload: MapLike = {
78
+ ...payload,
79
+ ...(this.customerIdentifiers ?? {}),
80
+ };
81
+ this.dl.pushEvent(eventName, newPayload);
68
82
  }
69
83
  }
70
84
 
@@ -239,16 +253,29 @@ class MagicPixelImpl {
239
253
  this.customerInfo = customerInfo;
240
254
  }
241
255
 
256
+ static setFirebaseAppInstanceId(instanceId: string): void {
257
+ this.customerIdentifiers.firebase_instance_id = instanceId;
258
+ }
259
+
260
+ static setFacebookClientId(fbp: string): void {
261
+ this.customerIdentifiers.fbp = fbp;
262
+ }
263
+
242
264
  static recordPageLoad(pageLoadInfo: AppPageLoad): void {
243
265
  pageLoadInfo.is_entry = this.firstAppLaunch ? 1 : 0;
244
266
  if (this.customerInfo) {
245
267
  const newPayload: MapLike = {
246
268
  ...pageLoadInfo,
247
269
  ...this.customerInfo,
270
+ ...(this.customerIdentifiers ?? {}),
248
271
  };
249
272
  this.dl.pushEvent('page_load', newPayload);
250
273
  } else {
251
- this.dl.pushEvent('page_load', pageLoadInfo);
274
+ const newPayload: MapLike = {
275
+ ...pageLoadInfo,
276
+ ...(this.customerIdentifiers ?? {}),
277
+ };
278
+ this.dl.pushEvent('page_load', newPayload);
252
279
  }
253
280
  this.firstAppLaunch = false;
254
281
  }
@@ -75,6 +75,22 @@ export class VisitIdProcessor {
75
75
  );
76
76
  }
77
77
 
78
+ static async getFacebookFBP(): Promise<string> {
79
+ try {
80
+ let fbp = await DataStore.getDataFromStorage<string>(Constants.KEY_FBP);
81
+
82
+ if (!fbp) {
83
+ fbp = `fb.1.${Date.now()}.${Date.now()}`;
84
+ }
85
+
86
+ await DataStore.storeData(Constants.KEY_FBP, fbp);
87
+ return fbp;
88
+ } catch (err) {
89
+ Logger.logError('Error initializing debug id.', err);
90
+ }
91
+ return '';
92
+ }
93
+
78
94
  static async initDebugId(): Promise<void> {
79
95
  try {
80
96
  let debugId = await DataStore.getDataFromStorage<string>(