@magicpixel/rn-mp-client-sdk 0.6.2 → 0.7.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 (39) hide show
  1. package/lib/commonjs/common/app-types.js.map +1 -1
  2. package/lib/commonjs/common/data-store.js +10 -0
  3. package/lib/commonjs/common/data-store.js.map +1 -1
  4. package/lib/commonjs/common/network-service.js +11 -5
  5. package/lib/commonjs/common/network-service.js.map +1 -1
  6. package/lib/commonjs/common/utils.js +17 -46
  7. package/lib/commonjs/common/utils.js.map +1 -1
  8. package/lib/commonjs/index.js +29 -2
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/processors/tag.processor.js +1 -1
  11. package/lib/commonjs/processors/tag.processor.js.map +1 -1
  12. package/lib/commonjs/processors/visit-id.processor.js +56 -87
  13. package/lib/commonjs/processors/visit-id.processor.js.map +1 -1
  14. package/lib/module/common/app-types.js.map +1 -1
  15. package/lib/module/common/data-store.js +10 -0
  16. package/lib/module/common/data-store.js.map +1 -1
  17. package/lib/module/common/network-service.js +11 -5
  18. package/lib/module/common/network-service.js.map +1 -1
  19. package/lib/module/common/utils.js +18 -47
  20. package/lib/module/common/utils.js.map +1 -1
  21. package/lib/module/index.js +28 -2
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/processors/tag.processor.js +1 -1
  24. package/lib/module/processors/tag.processor.js.map +1 -1
  25. package/lib/module/processors/visit-id.processor.js +49 -82
  26. package/lib/module/processors/visit-id.processor.js.map +1 -1
  27. package/lib/typescript/common/app-types.d.ts +1 -0
  28. package/lib/typescript/common/data-store.d.ts +3 -0
  29. package/lib/typescript/common/utils.d.ts +3 -4
  30. package/lib/typescript/index.d.ts +6 -3
  31. package/lib/typescript/processors/visit-id.processor.d.ts +4 -4
  32. package/package.json +27 -25
  33. package/src/common/app-types.ts +2 -0
  34. package/src/common/data-store.ts +10 -0
  35. package/src/common/network-service.ts +8 -2
  36. package/src/common/utils.ts +15 -62
  37. package/src/index.tsx +36 -5
  38. package/src/processors/tag.processor.ts +1 -1
  39. package/src/processors/visit-id.processor.ts +54 -96
@@ -4,67 +4,11 @@ import { Constants } from '../common/constants';
4
4
  import { Reporter } from '../common/reporter';
5
5
  import { NetworkService } from '../common/network-service';
6
6
  import { Utils } from '../common/utils';
7
- import { EventBus } from '../common/event-bus';
8
7
  export class VisitIdProcessor {
9
- static async init() {
10
- await this.initIdlEventListener();
11
- await this.initDebugId();
8
+ static async init(orgId) {
9
+ await this.initDebugId(orgId);
12
10
  await this.setOrResetVisitorId();
13
- await this.setOrResetVisitInfo();
14
- }
15
-
16
- static async initIdlEventListener() {
17
- EventBus.on('mp_idl_app_event', (channelName, eventPayload) => {
18
- try {
19
- if (!channelName || !eventPayload) {
20
- Logger.logError('Both event name and event payload is mandatory for processing idl events');
21
- return;
22
- }
23
-
24
- const eventName = eventPayload.client_ev_name;
25
- const attrInfoPayload = eventPayload.client_ev_payload ?? {};
26
- const deepPayload = (attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.payload) ?? {}; // is_entry, app_type,
27
-
28
- try {
29
- deepPayload['org_id'] = eventPayload === null || eventPayload === void 0 ? void 0 : eventPayload.org_id;
30
- deepPayload['event_id'] = eventPayload === null || eventPayload === void 0 ? void 0 : eventPayload.event_id;
31
- deepPayload['event_ts'] = eventPayload === null || eventPayload === void 0 ? void 0 : eventPayload.event_ts;
32
- } catch (e) {
33
- Logger.logError('Error enhancing internal attr payload');
34
- }
35
-
36
- const attrPayload = {
37
- pu: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.page_url,
38
- ru: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.campaign_ref,
39
- pt: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.page_title,
40
- en: attrInfoPayload.event_name,
41
- cid: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.campaign_id,
42
- rs: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.report_suite,
43
- v: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.client_sdk_version,
44
- vidl: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.idl_version,
45
- ev: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.event_val,
46
- ep: deepPayload,
47
- at: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.app_type,
48
- evId: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.event_id,
49
- evTs: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.event_ts,
50
- orgId: attrInfoPayload === null || attrInfoPayload === void 0 ? void 0 : attrInfoPayload.org_id,
51
- _mp_vid: DataStore.visitInfoToString(),
52
- _lmid: DataStore.getMpId(),
53
- _ldid: DataStore.getDeviceId(),
54
- _mpidl: JSON.stringify(DataStore.getVisitorInfoAsString()),
55
- is_entry: attrInfoPayload.is_entry ?? 0,
56
- app_type: attrInfoPayload.app_type
57
- };
58
-
59
- if (eventName === 'al') {
60
- attrPayload.pid = eventPayload === null || eventPayload === void 0 ? void 0 : eventPayload.profile_id;
61
- }
62
-
63
- Reporter.postAttrInfo(attrPayload);
64
- } catch (err) {
65
- Logger.logError('Error processing idl event: ', err);
66
- }
67
- });
11
+ await this.setOrResetVisitInfo(false);
68
12
  }
69
13
 
70
14
  static async getFacebookFBP() {
@@ -76,6 +20,7 @@ export class VisitIdProcessor {
76
20
  }
77
21
 
78
22
  await DataStore.storeData(Constants.KEY_FBP, fbp);
23
+ DataStore.addCommonCookie('_fbp', fbp);
79
24
  return fbp;
80
25
  } catch (err) {
81
26
  Logger.logError('Error initializing debug id.', err);
@@ -84,12 +29,17 @@ export class VisitIdProcessor {
84
29
  return '';
85
30
  }
86
31
 
87
- static async initDebugId() {
32
+ static async initDebugId(orgId) {
88
33
  try {
89
34
  let debugId = await DataStore.getDataFromStorage(Constants.KEY_MP_DEBUG_ID);
90
35
 
36
+ if (debugId && debugId.indexOf(orgId) !== 0) {
37
+ // re-generate debug id if it is not of the simple variety
38
+ debugId = undefined;
39
+ }
40
+
91
41
  if (!debugId) {
92
- debugId = Utils.getUniqueID();
42
+ debugId = Utils.getSimpleDebugId(orgId);
93
43
  }
94
44
 
95
45
  await DataStore.storeData(Constants.KEY_MP_DEBUG_ID, debugId);
@@ -99,31 +49,39 @@ export class VisitIdProcessor {
99
49
  }
100
50
  }
101
51
 
102
- static async setOrResetVisitInfo() {
52
+ static async setOrResetVisitInfo(incrementDepth) {
103
53
  try {
104
- const visitInfo = await DataStore.getDataFromStorage(Constants.KEY_MP_IDL_VISIT_ID_INFO);
54
+ let visitInfo = await DataStore.getDataFromStorage(Constants.KEY_MP_IDL_VISIT_ID_INFO);
105
55
 
106
56
  if (!visitInfo) {
107
- // may be first time visit, setup a new visit info object and return
108
- const newVisitInfo = {
57
+ // may be first time visit, set up a new visit info object and return
58
+ visitInfo = {
109
59
  visitId: Utils.getUniqueID(),
110
60
  visitCt: 1,
111
61
  visitDepth: 1,
112
62
  visitTs: Date.now(),
113
63
  visitVer: 1
114
64
  };
115
- DataStore.setVisitInfo(newVisitInfo);
116
- await DataStore.storeData(Constants.KEY_MP_IDL_VISIT_ID_INFO, newVisitInfo);
117
65
  } else {
118
66
  // reset visit id anyway, but retain the visitCt and depth setting
119
67
  visitInfo.visitId = Utils.getUniqueID();
120
- visitInfo.visitCt = visitInfo.visitCt + 1;
121
- visitInfo.visitDepth = 1;
68
+
69
+ if (incrementDepth) {
70
+ var _visitInfo;
71
+
72
+ visitInfo.visitDepth = (((_visitInfo = visitInfo) === null || _visitInfo === void 0 ? void 0 : _visitInfo.visitDepth) ?? 0) + 1;
73
+ } else {
74
+ visitInfo.visitCt = visitInfo.visitCt + 1;
75
+ visitInfo.visitDepth = 1;
76
+ }
77
+
122
78
  visitInfo.visitTs = Date.now();
123
79
  visitInfo.visitVer = 1;
124
- DataStore.setVisitInfo(visitInfo);
125
- await DataStore.storeData(Constants.KEY_MP_IDL_VISIT_ID_INFO, visitInfo);
126
80
  }
81
+
82
+ DataStore.setVisitInfo(visitInfo);
83
+ await DataStore.storeData(Constants.KEY_MP_IDL_VISIT_ID_INFO, visitInfo);
84
+ DataStore.addCommonCookie('_mp_vid', DataStore.visitInfoToString());
127
85
  } catch (err) {
128
86
  Logger.logError(err);
129
87
  DataStore.setVisitInfo(null);
@@ -131,24 +89,33 @@ export class VisitIdProcessor {
131
89
  }
132
90
  }
133
91
 
92
+ static async incrementVisitDepth() {
93
+ return this.setOrResetVisitInfo(true);
94
+ }
95
+
134
96
  static async setOrResetVisitorId() {
135
97
  try {
136
- const visitorInfoData = await DataStore.getDataFromStorage(Constants.KEY_MP_IDL_VISITOR_ID_INFO);
98
+ var _visitorInfoData;
137
99
 
138
- if (!visitorInfoData) {
139
- Logger.logDbg('VisitorInfo not found. Refreshing from server'); // get a new visit id and device id from server and store it in storage
100
+ let visitorInfoData = await DataStore.getDataFromStorage(Constants.KEY_MP_IDL_VISITOR_ID_INFO);
140
101
 
141
- const apiVisitInfo = await NetworkService.fetchIdlInfo(DataStore.getIdlUrl());
102
+ if (!visitorInfoData || visitorInfoData && ((_visitorInfoData = visitorInfoData) === null || _visitorInfoData === void 0 ? void 0 : _visitorInfoData.mId.indexOf('-')) === -1) {
103
+ Logger.logDbg('VisitorInfo not found. Refreshing from server'); // get a new visit id and device id from server and store it in storage
142
104
 
143
- if (!apiVisitInfo) {
144
- return;
145
- } else {
146
- DataStore.setVisitorInfo(apiVisitInfo); // store to db as well
105
+ visitorInfoData = await NetworkService.fetchIdlInfo(DataStore.getIdlUrl());
106
+ }
147
107
 
148
- await DataStore.storeData(Constants.KEY_MP_IDL_VISITOR_ID_INFO, apiVisitInfo);
149
- }
108
+ if (!visitorInfoData) {
109
+ return;
150
110
  } else {
151
- DataStore.setVisitorInfo(visitorInfoData);
111
+ DataStore.setVisitorInfo(visitorInfoData); // store to db as well
112
+
113
+ await DataStore.storeData(Constants.KEY_MP_IDL_VISITOR_ID_INFO, visitorInfoData);
114
+ const cookieValue = encodeURIComponent(JSON.stringify(visitorInfoData));
115
+ DataStore.addCommonCookie('_mplidl', cookieValue);
116
+ DataStore.addCommonCookie('_mpidl', cookieValue);
117
+ DataStore.addCommonCookie('_lmid', visitorInfoData.mId);
118
+ DataStore.addCommonCookie('_ldid', visitorInfoData.dId);
152
119
  }
153
120
  } catch (err) {
154
121
  Logger.logError(err);
@@ -1 +1 @@
1
- {"version":3,"names":["Logger","DataStore","Constants","Reporter","NetworkService","Utils","EventBus","VisitIdProcessor","init","initIdlEventListener","initDebugId","setOrResetVisitorId","setOrResetVisitInfo","on","channelName","eventPayload","logError","eventName","client_ev_name","attrInfoPayload","client_ev_payload","deepPayload","payload","org_id","event_id","event_ts","e","attrPayload","pu","page_url","ru","campaign_ref","pt","page_title","en","event_name","cid","campaign_id","rs","report_suite","v","client_sdk_version","vidl","idl_version","ev","event_val","ep","at","app_type","evId","evTs","orgId","_mp_vid","visitInfoToString","_lmid","getMpId","_ldid","getDeviceId","_mpidl","JSON","stringify","getVisitorInfoAsString","is_entry","pid","profile_id","postAttrInfo","err","getFacebookFBP","fbp","getDataFromStorage","KEY_FBP","Date","now","storeData","debugId","KEY_MP_DEBUG_ID","getUniqueID","setDebugId","visitInfo","KEY_MP_IDL_VISIT_ID_INFO","newVisitInfo","visitId","visitCt","visitDepth","visitTs","visitVer","setVisitInfo","reportError","visitorInfoData","KEY_MP_IDL_VISITOR_ID_INFO","logDbg","apiVisitInfo","fetchIdlInfo","getIdlUrl","setVisitorInfo"],"sources":["visit-id.processor.ts"],"sourcesContent":["import { Logger } from '../common/logger';\nimport { DataStore } from '../common/data-store';\nimport { Constants } from '../common/constants';\nimport { Reporter } from '../common/reporter';\nimport { NetworkService } from '../common/network-service';\nimport type { VisitInfo, VisitorInfo } from '../common/app-types';\nimport { Utils } from '../common/utils';\nimport { EventBus } from '../common/event-bus';\n\nexport class VisitIdProcessor {\n static async init(): Promise<void> {\n await this.initIdlEventListener();\n await this.initDebugId();\n await this.setOrResetVisitorId();\n await this.setOrResetVisitInfo();\n }\n\n static async initIdlEventListener(): Promise<void> {\n EventBus.on(\n 'mp_idl_app_event',\n (channelName: string, eventPayload: Record<string, string>) => {\n try {\n if (!channelName || !eventPayload) {\n Logger.logError(\n 'Both event name and event payload is mandatory for processing idl events'\n );\n return;\n }\n\n const eventName = eventPayload.client_ev_name;\n const attrInfoPayload: any = eventPayload.client_ev_payload ?? {};\n const deepPayload: any = attrInfoPayload?.payload ?? {};\n\n // is_entry, app_type,\n try {\n deepPayload['org_id'] = eventPayload?.org_id;\n deepPayload['event_id'] = eventPayload?.event_id;\n deepPayload['event_ts'] = eventPayload?.event_ts;\n } catch (e) {\n Logger.logError('Error enhancing internal attr payload');\n }\n\n const attrPayload: any = {\n pu: attrInfoPayload?.page_url,\n ru: attrInfoPayload?.campaign_ref,\n pt: attrInfoPayload?.page_title,\n en: attrInfoPayload.event_name,\n cid: attrInfoPayload?.campaign_id,\n rs: attrInfoPayload?.report_suite,\n v: attrInfoPayload?.client_sdk_version,\n vidl: attrInfoPayload?.idl_version,\n ev: attrInfoPayload?.event_val,\n ep: deepPayload,\n at: attrInfoPayload?.app_type,\n evId: attrInfoPayload?.event_id,\n evTs: attrInfoPayload?.event_ts,\n orgId: attrInfoPayload?.org_id,\n _mp_vid: DataStore.visitInfoToString(),\n _lmid: DataStore.getMpId(),\n _ldid: DataStore.getDeviceId(),\n _mpidl: JSON.stringify(DataStore.getVisitorInfoAsString()),\n is_entry: attrInfoPayload.is_entry ?? 0,\n app_type: attrInfoPayload.app_type,\n };\n\n if (eventName === 'al') {\n attrPayload.pid = eventPayload?.profile_id;\n }\n\n Reporter.postAttrInfo(attrPayload);\n } catch (err) {\n Logger.logError('Error processing idl event: ', err);\n }\n }\n );\n }\n\n static async getFacebookFBP(): Promise<string> {\n try {\n let fbp = await DataStore.getDataFromStorage<string>(Constants.KEY_FBP);\n\n if (!fbp) {\n fbp = `fb.1.${Date.now()}.${Date.now()}`;\n }\n\n await DataStore.storeData(Constants.KEY_FBP, fbp);\n return fbp;\n } catch (err) {\n Logger.logError('Error initializing debug id.', err);\n }\n return '';\n }\n\n static async initDebugId(): Promise<void> {\n try {\n let debugId = await DataStore.getDataFromStorage<string>(\n Constants.KEY_MP_DEBUG_ID\n );\n if (!debugId) {\n debugId = Utils.getUniqueID();\n }\n await DataStore.storeData(Constants.KEY_MP_DEBUG_ID, debugId);\n DataStore.setDebugId(debugId);\n } catch (err) {\n Logger.logError('Error initializing debug id.', err);\n }\n }\n\n static async setOrResetVisitInfo(): Promise<void> {\n try {\n const visitInfo: VisitInfo = await DataStore.getDataFromStorage(\n Constants.KEY_MP_IDL_VISIT_ID_INFO\n );\n\n if (!visitInfo) {\n // may be first time visit, setup a new visit info object and return\n const newVisitInfo: VisitInfo = {\n visitId: Utils.getUniqueID(),\n visitCt: 1,\n visitDepth: 1,\n visitTs: Date.now(),\n visitVer: 1,\n };\n DataStore.setVisitInfo(newVisitInfo);\n await DataStore.storeData(\n Constants.KEY_MP_IDL_VISIT_ID_INFO,\n newVisitInfo\n );\n } else {\n // reset visit id anyway, but retain the visitCt and depth setting\n visitInfo.visitId = Utils.getUniqueID();\n visitInfo.visitCt = visitInfo.visitCt + 1;\n visitInfo.visitDepth = 1;\n visitInfo.visitTs = Date.now();\n visitInfo.visitVer = 1;\n DataStore.setVisitInfo(visitInfo);\n await DataStore.storeData(\n Constants.KEY_MP_IDL_VISIT_ID_INFO,\n visitInfo\n );\n }\n } catch (err) {\n Logger.logError(err);\n DataStore.setVisitInfo(null);\n Reporter.reportError('setOrResetVisitInfo', err);\n }\n }\n\n static async setOrResetVisitorId(): Promise<void> {\n try {\n const visitorInfoData: VisitorInfo = await DataStore.getDataFromStorage(\n Constants.KEY_MP_IDL_VISITOR_ID_INFO\n );\n\n if (!visitorInfoData) {\n Logger.logDbg('VisitorInfo not found. Refreshing from server');\n // get a new visit id and device id from server and store it in storage\n const apiVisitInfo = await NetworkService.fetchIdlInfo(\n DataStore.getIdlUrl()\n );\n if (!apiVisitInfo) {\n return;\n } else {\n DataStore.setVisitorInfo(apiVisitInfo);\n // store to db as well\n await DataStore.storeData(\n Constants.KEY_MP_IDL_VISITOR_ID_INFO,\n apiVisitInfo\n );\n }\n } else {\n DataStore.setVisitorInfo(visitorInfoData);\n }\n } catch (err) {\n Logger.logError(err);\n DataStore.setVisitorInfo(null);\n Reporter.reportError('setOrResetVisitorId', err);\n }\n }\n}\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,kBAAvB;AACA,SAASC,SAAT,QAA0B,sBAA1B;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,cAAT,QAA+B,2BAA/B;AAEA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SAASC,QAAT,QAAyB,qBAAzB;AAEA,OAAO,MAAMC,gBAAN,CAAuB;EACX,aAAJC,IAAI,GAAkB;IACjC,MAAM,KAAKC,oBAAL,EAAN;IACA,MAAM,KAAKC,WAAL,EAAN;IACA,MAAM,KAAKC,mBAAL,EAAN;IACA,MAAM,KAAKC,mBAAL,EAAN;EACD;;EAEgC,aAApBH,oBAAoB,GAAkB;IACjDH,QAAQ,CAACO,EAAT,CACE,kBADF,EAEE,CAACC,WAAD,EAAsBC,YAAtB,KAA+D;MAC7D,IAAI;QACF,IAAI,CAACD,WAAD,IAAgB,CAACC,YAArB,EAAmC;UACjCf,MAAM,CAACgB,QAAP,CACE,0EADF;UAGA;QACD;;QAED,MAAMC,SAAS,GAAGF,YAAY,CAACG,cAA/B;QACA,MAAMC,eAAoB,GAAGJ,YAAY,CAACK,iBAAb,IAAkC,EAA/D;QACA,MAAMC,WAAgB,GAAG,CAAAF,eAAe,SAAf,IAAAA,eAAe,WAAf,YAAAA,eAAe,CAAEG,OAAjB,KAA4B,EAArD,CAVE,CAYF;;Q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uBR,SAAvB;QACA,MAAM7E,SAAS,CAACwE,SAAV,CACJvE,SAAS,CAAC6E,wBADN,EAEJD,SAFI,CAAN;MAID;IACF,CAhCD,CAgCE,OAAOZ,GAAP,EAAY;MACZlE,MAAM,CAACgB,QAAP,CAAgBkD,GAAhB;MACAjE,SAAS,CAACqF,YAAV,CAAuB,IAAvB;MACAnF,QAAQ,CAACoF,WAAT,CAAqB,qBAArB,EAA4CrB,GAA5C;IACD;EACF;;EAE+B,aAAnBvD,mBAAmB,GAAkB;IAChD,IAAI;MACF,MAAM6E,eAA4B,GAAG,MAAMvF,SAAS,CAACoE,kBAAV,CACzCnE,SAAS,CAACuF,0BAD+B,CAA3C;;MAIA,IAAI,CAACD,eAAL,EAAsB;QACpBxF,MAAM,CAAC0F,MAAP,CAAc,+CAAd,EADoB,CAEpB;;QACA,MAAMC,YAAY,GAAG,MAAMvF,cAAc,CAACwF,YAAf,CACzB3F,SAAS,CAAC4F,SAAV,EADyB,CAA3B;;QAGA,IAAI,CAACF,YAAL,EAAmB;UACjB;QACD,CAFD,MAEO;UACL1F,SAAS,CAAC6F,cAAV,CAAyBH,YAAzB,EADK,CAEL;;UACA,MAAM1F,SAAS,CAACwE,SAAV,CACJvE,SAAS,CAACuF,0BADN,EAEJE,YAFI,CAAN;QAID;MACF,CAhBD,MAgBO;QACL1F,SAAS,CAAC6F,cAAV,CAAyBN,eAAzB;MACD;IACF,CAxBD,CAwBE,OAAOtB,GAAP,EAAY;MACZlE,MAAM,CAACgB,QAAP,CAAgBkD,GAAhB;MACAjE,SAAS,CAAC6F,cAAV,CAAyB,IAAzB;MACA3F,QAAQ,CAACoF,WAAT,CAAqB,qBAArB,EAA4CrB,GAA5C;IACD;EACF;;AAzK2B"}
1
+ {"version":3,"names":["Logger","DataStore","Constants","Reporter","NetworkService","Utils","VisitIdProcessor","init","orgId","initDebugId","setOrResetVisitorId","setOrResetVisitInfo","getFacebookFBP","fbp","getDataFromStorage","KEY_FBP","Date","now","storeData","addCommonCookie","err","logError","debugId","KEY_MP_DEBUG_ID","indexOf","undefined","getSimpleDebugId","setDebugId","incrementDepth","visitInfo","KEY_MP_IDL_VISIT_ID_INFO","visitId","getUniqueID","visitCt","visitDepth","visitTs","visitVer","setVisitInfo","visitInfoToString","reportError","incrementVisitDepth","visitorInfoData","KEY_MP_IDL_VISITOR_ID_INFO","mId","logDbg","fetchIdlInfo","getIdlUrl","setVisitorInfo","cookieValue","encodeURIComponent","JSON","stringify","dId"],"sources":["visit-id.processor.ts"],"sourcesContent":["import { Logger } from '../common/logger';\nimport { DataStore } from '../common/data-store';\nimport { Constants } from '../common/constants';\nimport { Reporter } from '../common/reporter';\nimport { NetworkService } from '../common/network-service';\nimport type { VisitInfo, VisitorInfo } from '../common/app-types';\nimport { Utils } from '../common/utils';\n\nexport class VisitIdProcessor {\n static async init(orgId: string): Promise<void> {\n await this.initDebugId(orgId);\n await this.setOrResetVisitorId();\n await this.setOrResetVisitInfo(false);\n }\n\n static async getFacebookFBP(): Promise<string> {\n try {\n let fbp = await DataStore.getDataFromStorage<string>(Constants.KEY_FBP);\n\n if (!fbp) {\n fbp = `fb.1.${Date.now()}.${Date.now()}`;\n }\n\n await DataStore.storeData(Constants.KEY_FBP, fbp);\n\n DataStore.addCommonCookie('_fbp', fbp);\n\n return fbp;\n } catch (err) {\n Logger.logError('Error initializing debug id.', err);\n }\n return '';\n }\n\n static async initDebugId(orgId: string): Promise<void> {\n try {\n let debugId = await DataStore.getDataFromStorage<string>(\n Constants.KEY_MP_DEBUG_ID\n );\n\n if (debugId && debugId.indexOf(orgId) !== 0) {\n // re-generate debug id if it is not of the simple variety\n debugId = undefined;\n }\n\n if (!debugId) {\n debugId = Utils.getSimpleDebugId(orgId);\n }\n\n await DataStore.storeData(Constants.KEY_MP_DEBUG_ID, debugId);\n DataStore.setDebugId(debugId);\n } catch (err) {\n Logger.logError('Error initializing debug id.', err);\n }\n }\n\n static async setOrResetVisitInfo(incrementDepth: boolean): Promise<void> {\n try {\n let visitInfo: VisitInfo = await DataStore.getDataFromStorage(\n Constants.KEY_MP_IDL_VISIT_ID_INFO\n );\n\n if (!visitInfo) {\n // may be first time visit, set up a new visit info object and return\n visitInfo = {\n visitId: Utils.getUniqueID(),\n visitCt: 1,\n visitDepth: 1,\n visitTs: Date.now(),\n visitVer: 1,\n };\n } else {\n // reset visit id anyway, but retain the visitCt and depth setting\n visitInfo.visitId = Utils.getUniqueID();\n if (incrementDepth) {\n visitInfo.visitDepth = (visitInfo?.visitDepth ?? 0) + 1;\n } else {\n visitInfo.visitCt = visitInfo.visitCt + 1;\n visitInfo.visitDepth = 1;\n }\n visitInfo.visitTs = Date.now();\n visitInfo.visitVer = 1;\n }\n\n DataStore.setVisitInfo(visitInfo);\n await DataStore.storeData(Constants.KEY_MP_IDL_VISIT_ID_INFO, visitInfo);\n DataStore.addCommonCookie('_mp_vid', DataStore.visitInfoToString());\n } catch (err) {\n Logger.logError(err);\n DataStore.setVisitInfo(null);\n Reporter.reportError('setOrResetVisitInfo', err);\n }\n }\n\n static async incrementVisitDepth(): Promise<void> {\n return this.setOrResetVisitInfo(true);\n }\n\n static async setOrResetVisitorId(): Promise<void> {\n try {\n let visitorInfoData: VisitorInfo = await DataStore.getDataFromStorage(\n Constants.KEY_MP_IDL_VISITOR_ID_INFO\n );\n\n if (\n !visitorInfoData ||\n (visitorInfoData && visitorInfoData?.mId.indexOf('-') === -1)\n ) {\n Logger.logDbg('VisitorInfo not found. Refreshing from server');\n // get a new visit id and device id from server and store it in storage\n visitorInfoData = await NetworkService.fetchIdlInfo(\n DataStore.getIdlUrl()\n );\n }\n\n if (!visitorInfoData) {\n return;\n } else {\n DataStore.setVisitorInfo(visitorInfoData);\n // store to db as well\n await DataStore.storeData(\n Constants.KEY_MP_IDL_VISITOR_ID_INFO,\n visitorInfoData\n );\n\n const cookieValue = encodeURIComponent(JSON.stringify(visitorInfoData));\n DataStore.addCommonCookie('_mplidl', cookieValue);\n DataStore.addCommonCookie('_mpidl', cookieValue);\n DataStore.addCommonCookie('_lmid', visitorInfoData.mId);\n DataStore.addCommonCookie('_ldid', visitorInfoData.dId);\n }\n } catch (err) {\n Logger.logError(err);\n DataStore.setVisitorInfo(null);\n Reporter.reportError('setOrResetVisitorId', err);\n }\n }\n}\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,kBAAvB;AACA,SAASC,SAAT,QAA0B,sBAA1B;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,cAAT,QAA+B,2BAA/B;AAEA,SAASC,KAAT,QAAsB,iBAAtB;AAEA,OAAO,MAAMC,gBAAN,CAAuB;EACX,aAAJC,IAAI,CAACC,KAAD,EAA+B;IAC9C,MAAM,KAAKC,WAAL,CAAiBD,KAAjB,CAAN;IACA,MAAM,KAAKE,mBAAL,EAAN;IACA,MAAM,KAAKC,mBAAL,CAAyB,KAAzB,CAAN;EACD;;EAE0B,aAAdC,cAAc,GAAoB;IAC7C,IAAI;MACF,IAAIC,GAAG,GAAG,MAAMZ,SAAS,CAACa,kBAAV,CAAqCZ,SAAS,CAACa,OAA/C,CAAhB;;MAEA,IAAI,CAACF,GAAL,EAAU;QACRA,GAAG,GAAI,QAAOG,IAAI,CAACC,GAAL,EAAW,IAAGD,IAAI,CAACC,GAAL,EAAW,EAAvC;MACD;;MAED,MAAMhB,SAAS,CAACiB,SAAV,CAAoBhB,SAAS,CAACa,OAA9B,EAAuCF,GAAvC,CAAN;MAEAZ,SAAS,CAACkB,eAAV,CAA0B,MAA1B,EAAkCN,GAAlC;MAEA,OAAOA,GAAP;IACD,CAZD,CAYE,OAAOO,GAAP,EAAY;MACZpB,MAAM,CAACqB,QAAP,CAAgB,8BAAhB,EAAgDD,GAAhD;IACD;;IACD,OAAO,EAAP;EACD;;EAEuB,aAAXX,WAAW,CAACD,KAAD,EAA+B;IACrD,IAAI;MACF,IAAIc,OAAO,GAAG,MAAMrB,SAAS,CAACa,kBAAV,CAClBZ,SAAS,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f,CAAD,CAAtC;QACAxC,SAAS,CAACkB,eAAV,CAA0B,SAA1B,EAAqC6B,WAArC;QACA/C,SAAS,CAACkB,eAAV,CAA0B,QAA1B,EAAoC6B,WAApC;QACA/C,SAAS,CAACkB,eAAV,CAA0B,OAA1B,EAAmCsB,eAAe,CAACE,GAAnD;QACA1C,SAAS,CAACkB,eAAV,CAA0B,OAA1B,EAAmCsB,eAAe,CAACW,GAAnD;MACD;IACF,CAhCD,CAgCE,OAAOhC,GAAP,EAAY;MACZpB,MAAM,CAACqB,QAAP,CAAgBD,GAAhB;MACAnB,SAAS,CAAC8C,cAAV,CAAyB,IAAzB;MACA5C,QAAQ,CAACoC,WAAT,CAAqB,qBAArB,EAA4CnB,GAA5C;IACD;EACF;;AAhI2B"}
@@ -98,5 +98,6 @@ export interface SdkInitOptions {
98
98
  projectId: string;
99
99
  baseUrl: string;
100
100
  device_type?: string;
101
+ app_version?: string;
101
102
  }
102
103
  export declare type EventBusCallback = (event: string, payload: any) => void;
@@ -22,6 +22,7 @@ export declare class DataStore {
22
22
  private static interestedClientSideEvents;
23
23
  private static interestedServerSideEvents;
24
24
  private static interestedAllEvents;
25
+ private static commonCookies;
25
26
  static init(clientSdk: MpClientSdk): Promise<void>;
26
27
  static resetCollectorUrl(baseCollectorUrl: string, sdkEnv: string, vendorId: string, projectId: string): boolean;
27
28
  static enQueueTMFire(sseOnly: boolean, name: string, dcrName: string, eventId: string, dcrPayload?: Record<string, any>): void;
@@ -52,6 +53,8 @@ export declare class DataStore {
52
53
  static getSdkVersion(): string;
53
54
  static setDebugId(dbgId: string): void;
54
55
  static shouldFireSstForEvent(eventName: string): boolean;
56
+ static addCommonCookie(key: string, value: string): void;
57
+ static getCommonCookies(): Record<string, string>;
55
58
  static getUrlInfo(): UrlInfo;
56
59
  static getSdkTags(): MapLike<ClientSdkTagItem>;
57
60
  static getSdkProviders(): MapLike<ClientSdkPrItem>;
@@ -33,10 +33,9 @@ export declare class Utils {
33
33
  static convertToRegex(input: string, ignoreCase: boolean, fullMatch: boolean): RegExp;
34
34
  static safeExecute(fn: (payload: any) => any, payload: any): any;
35
35
  static getUniqueID(): string;
36
+ static getSimpleDebugId(prefix?: string): string;
37
+ static randomNumber(min: number, max: number): number;
36
38
  static unFlattenResourceParams<T extends BaseResourceParamType>(input: T[]): MapLike<T>;
37
- static unflattenObject(obj: Record<string, any>): Record<string, any>;
39
+ static unFlattenObject(obj: any): Record<string, any>;
38
40
  static flattenObject(obj: any): Record<string, any>;
39
- private static flatten;
40
- static keyIdentity(key: any): any;
41
- static isBuffer(obj: any): boolean;
42
41
  }
@@ -8,12 +8,15 @@ declare class MagicPixelImpl {
8
8
  static init(options: SdkInitOptions): Promise<void>;
9
9
  static recordEvent(eventName: string, payload: MapLike): void;
10
10
  static ready(): void;
11
- static checkAndFireTM(): Promise<void>;
12
- static runTM(sseOnly: boolean, triggerName: string, evtName: string, evtId: string, eventData?: Record<string, any>): Promise<void>;
13
- static _fireTM(envName: string, envId: string, evtName: string, evtId: string): void;
11
+ static getDebugId(): string;
12
+ private static checkAndFireTM;
13
+ private static runTM;
14
+ private static _fireTM;
15
+ private static _fireTMPrivate;
14
16
  static setCustomerInfo(customerInfo: AppCustomerInfo): void;
15
17
  static setFirebaseAppInstanceId(instanceId: string): void;
16
18
  static setFacebookClientId(fbp: string): void;
19
+ private static setAppVersion;
17
20
  static recordPageLoad(pageLoadInfo: AppPageLoad): void;
18
21
  }
19
22
  export declare const MagicPixelEventBus: typeof EventBus;
@@ -1,8 +1,8 @@
1
1
  export declare class VisitIdProcessor {
2
- static init(): Promise<void>;
3
- static initIdlEventListener(): Promise<void>;
2
+ static init(orgId: string): Promise<void>;
4
3
  static getFacebookFBP(): Promise<string>;
5
- static initDebugId(): Promise<void>;
6
- static setOrResetVisitInfo(): Promise<void>;
4
+ static initDebugId(orgId: string): Promise<void>;
5
+ static setOrResetVisitInfo(incrementDepth: boolean): Promise<void>;
6
+ static incrementVisitDepth(): Promise<void>;
7
7
  static setOrResetVisitorId(): Promise<void>;
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicpixel/rn-mp-client-sdk",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "test",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -29,7 +29,8 @@
29
29
  "release": "release-it",
30
30
  "example": "yarn --cwd example",
31
31
  "bootstrap": "yarn example && yarn && yarn example pods",
32
- "postpublish": "node quick-version-increment.js"
32
+ "postpublish": "node quick-version-increment.js",
33
+ "localpublish": "npm publish --@magicpixel:registry=http://localhost:4873 && npm run postpublish"
33
34
  },
34
35
  "keywords": [
35
36
  "react-native",
@@ -48,29 +49,30 @@
48
49
  "access": "public"
49
50
  },
50
51
  "devDependencies": {
51
- "@arkweid/lefthook": "^0.7.7",
52
- "@babel/eslint-parser": "^7.18.2",
53
- "@commitlint/config-conventional": "^17.0.2",
54
- "@react-native-community/eslint-config": "^3.0.2",
55
- "@release-it/conventional-changelog": "^5.0.0",
56
- "@types/flat": "^5.0.2",
52
+ "@arkweid/lefthook": "0.7.7",
53
+ "@babel/eslint-parser": "7.19.1",
54
+ "@commitlint/config-conventional": "17.1.0",
55
+ "@react-native-community/eslint-config": "3.1.0",
56
+ "@release-it/conventional-changelog": "5.1.0",
57
+ "@types/flat": "5.0.2",
57
58
  "@types/jest": "29.0.3",
58
59
  "@types/react": "~17.0.21",
59
60
  "@types/react-native": "0.68.0",
60
- "commitlint": "^17.0.2",
61
- "eslint": "^8.4.1",
62
- "eslint-config-prettier": "^8.5.0",
63
- "eslint-plugin-prettier": "^4.0.0",
61
+ "@types/uuid": "9.0.0",
62
+ "commitlint": "17.1.2",
63
+ "eslint": "8.23.1",
64
+ "eslint-config-prettier": "8.5.0",
65
+ "eslint-plugin-prettier": "4.2.1",
64
66
  "jest": "29.1.1",
65
- "pod-install": "^0.1.0",
66
- "prettier": "^2.0.5",
67
+ "pod-install": "0.1.38",
68
+ "prettier": "2.7.1",
67
69
  "react": "17.0.2",
68
70
  "react-native": "0.68.2",
69
- "react-native-builder-bob": "^0.18.3",
70
- "release-it": "^15.0.0",
71
- "ts-jest": "^29.0.2",
72
- "tsconfig-paths": "^4.1.0",
73
- "typescript": "^4.5.2"
71
+ "react-native-builder-bob": "0.18.3",
72
+ "release-it": "15.4.2",
73
+ "ts-jest": "29.0.2",
74
+ "tsconfig-paths": "4.1.0",
75
+ "typescript": "4.8.3"
74
76
  },
75
77
  "resolutions": {
76
78
  "@types/react": "17.0.21"
@@ -157,11 +159,11 @@
157
159
  ]
158
160
  },
159
161
  "dependencies": {
160
- "@react-native-async-storage/async-storage": "^1.17.10",
161
- "flat": "^5.0.2",
162
- "nanoid": "^4.0.0",
163
- "performant-array-to-tree": "^1.11.0",
164
- "react-native-event-listeners": "^1.0.7",
165
- "ts-node": "^10.9.1"
162
+ "@react-native-async-storage/async-storage": "1.17.10",
163
+ "flat": "5.0.2",
164
+ "nanoid": "4.0.0",
165
+ "performant-array-to-tree": "1.11.0",
166
+ "ts-node": "10.9.1",
167
+ "uuid": "9.0.0"
166
168
  }
167
169
  }
@@ -125,6 +125,8 @@ export interface SdkInitOptions {
125
125
  baseUrl: string;
126
126
 
127
127
  device_type?: string;
128
+
129
+ app_version?: string;
128
130
  }
129
131
 
130
132
  export type EventBusCallback = (event: string, payload: any) => void;
@@ -44,6 +44,8 @@ export class DataStore {
44
44
  private static interestedServerSideEvents: string[] = [];
45
45
  private static interestedAllEvents: string[] = [];
46
46
 
47
+ private static commonCookies: Record<string, string> = {};
48
+
47
49
  static async init(clientSdk: MpClientSdk): Promise<void> {
48
50
  this.clientSdk = clientSdk;
49
51
  this.setMpEnv(clientSdk?.s?.ev === 'staging' ? 'stg' : 'prd');
@@ -227,6 +229,14 @@ export class DataStore {
227
229
  return this.clientSdk?.sseMpDlE?.indexOf(eventName) > -1;
228
230
  }
229
231
 
232
+ static addCommonCookie(key: string, value: string): void {
233
+ this.commonCookies[key] = value;
234
+ }
235
+
236
+ static getCommonCookies(): Record<string, string> {
237
+ return this.commonCookies;
238
+ }
239
+
230
240
  static getUrlInfo(): UrlInfo {
231
241
  return this.urls;
232
242
  }
@@ -28,7 +28,7 @@ export class NetworkService {
28
28
  if (response) {
29
29
  const sdkJson: MpClientSdk = await response.json();
30
30
  Logger.logDbg('Client Sdk:: ', sdkJson);
31
- // sdkJson.s.c_url = 'http://localhost:3001';
31
+ sdkJson.s.c_url = 'http://localhost:3003';
32
32
  await DataStore.init(sdkJson);
33
33
  }
34
34
  } catch (err) {
@@ -60,16 +60,22 @@ export class NetworkService {
60
60
  );
61
61
  if (method === 'get') {
62
62
  return await fetch(url, {
63
+ method: 'GET',
63
64
  headers: {
65
+ 'Content-Type': 'application/json',
64
66
  'cache-control': 'no-store',
67
+ 'x-dbg': 'trace',
68
+ ...DataStore.getCommonCookies(),
65
69
  },
66
70
  });
67
71
  } else if (method === 'post') {
68
72
  return await fetch(url, {
69
73
  method: 'POST',
70
74
  headers: {
71
- 'Content-Type': 'text/plain',
75
+ 'Content-Type': 'application/json',
72
76
  'cache-control': 'no-store',
77
+ 'x-dbg': 'trace',
78
+ ...DataStore.getCommonCookies(),
73
79
  },
74
80
  body: JSON.stringify(body ?? '{}'),
75
81
  });
@@ -6,7 +6,7 @@ import type {
6
6
  TFType,
7
7
  } from '../models/mp-client-sdk';
8
8
  import type { MapLike } from './app-types';
9
- import { unflatten } from 'flat';
9
+ import { flatten, unflatten } from 'flat';
10
10
  import { EventBus } from './event-bus';
11
11
  import { Dimensions, ScaledSize } from 'react-native';
12
12
 
@@ -190,6 +190,14 @@ export class Utils {
190
190
  return Constants.LARGE_RANDOM_POOL();
191
191
  }
192
192
 
193
+ static getSimpleDebugId(prefix?: string): string {
194
+ return `${prefix ?? ''}${this.randomNumber(100000000, 99999999999)}`;
195
+ }
196
+
197
+ static randomNumber(min: number, max: number): number {
198
+ return Math.ceil(Math.random() * (max - min) + min);
199
+ }
200
+
193
201
  static unFlattenResourceParams<T extends BaseResourceParamType>(
194
202
  input: T[]
195
203
  ): MapLike<T> {
@@ -227,72 +235,17 @@ export class Utils {
227
235
  return op;
228
236
  }
229
237
 
230
- static unflattenObject(obj: Record<string, any>): Record<string, any> {
231
- try {
232
- return unflatten(obj, { object: false, delimiter: '.' });
233
- } catch (e) {}
234
- return null;
238
+ static unFlattenObject(obj: any): Record<string, any> {
239
+ if (!obj) {
240
+ return {};
241
+ }
242
+ return unflatten(obj, { object: false, delimiter: '.' });
235
243
  }
236
244
 
237
245
  static flattenObject(obj: any): Record<string, any> {
238
246
  if (!obj) {
239
247
  return {};
240
248
  }
241
- return this.flatten(obj, { maxDepth: 5, safe: true });
242
- }
243
-
244
- private static flatten(target: any, opts: any): any {
245
- opts = opts || {};
246
-
247
- const delimiter = opts.delimiter || '.';
248
- const maxDepth = opts.maxDepth;
249
- const transformKey = opts.transformKey || this.keyIdentity;
250
- const output: any = {};
251
-
252
- const step = (object: any, prev?: any, currentDepth?: any): any => {
253
- currentDepth = currentDepth || 1;
254
- Object.keys(object).forEach((key) => {
255
- const value = object[key];
256
- const isarray = opts.safe && Array.isArray(value);
257
- const type = Object.prototype.toString.call(value);
258
- const isBuffer = this.isBuffer(value);
259
-
260
- const isobject =
261
- type === '[object Object]' || type === '[object Array]';
262
-
263
- const newKey = prev
264
- ? prev + delimiter + transformKey(key)
265
- : transformKey(key);
266
-
267
- if (
268
- !isarray &&
269
- !isBuffer &&
270
- isobject &&
271
- Object.keys(value).length &&
272
- (!opts.maxDepth || currentDepth < maxDepth)
273
- ) {
274
- return step(value, newKey, currentDepth + 1);
275
- }
276
-
277
- output[newKey] = value;
278
- });
279
- };
280
-
281
- step(target);
282
-
283
- return output;
284
- }
285
-
286
- static keyIdentity(key: any): any {
287
- return key;
288
- }
289
-
290
- static isBuffer(obj: any): boolean {
291
- return (
292
- obj &&
293
- obj.constructor &&
294
- typeof obj.constructor.isBuffer === 'function' &&
295
- obj.constructor.isBuffer(obj)
296
- );
249
+ return flatten(obj, { maxDepth: 5, safe: true });
297
250
  }
298
251
  }