mapp-intelligence-reactnative-plugin 1.0.1 → 1.0.3

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 (45) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/gradle.properties +4 -5
  3. package/android/src/main/java/com/mappinteligenceplugin/mapper/Util.kt +12 -4
  4. package/ios/MappinteligencePlugin.mm +3 -2
  5. package/lib/commonjs/Converters.js +1 -1
  6. package/lib/commonjs/Converters.js.map +1 -1
  7. package/lib/commonjs/DataTypes.js +10 -2
  8. package/lib/commonjs/DataTypes.js.map +1 -1
  9. package/lib/commonjs/GlobalErrorHandler.js +2 -6
  10. package/lib/commonjs/GlobalErrorHandler.js.map +1 -1
  11. package/lib/commonjs/MappIntelligencePlugin.js +296 -0
  12. package/lib/commonjs/MappIntelligencePlugin.js.map +1 -0
  13. package/lib/commonjs/UseWebTracking.js +6 -24
  14. package/lib/commonjs/UseWebTracking.js.map +1 -1
  15. package/lib/commonjs/index.js +14 -390
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/promiseRejectionHandler.js.map +1 -1
  18. package/lib/module/Converters.js +1 -1
  19. package/lib/module/Converters.js.map +1 -1
  20. package/lib/module/DataTypes.js +10 -2
  21. package/lib/module/DataTypes.js.map +1 -1
  22. package/lib/module/GlobalErrorHandler.js +2 -6
  23. package/lib/module/GlobalErrorHandler.js.map +1 -1
  24. package/lib/module/MappIntelligencePlugin.js +290 -0
  25. package/lib/module/MappIntelligencePlugin.js.map +1 -0
  26. package/lib/module/UseWebTracking.js +6 -23
  27. package/lib/module/UseWebTracking.js.map +1 -1
  28. package/lib/module/index.js +2 -320
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/module/promiseRejectionHandler.js.map +1 -1
  31. package/lib/typescript/src/DataTypes.d.ts +6 -6
  32. package/lib/typescript/src/DataTypes.d.ts.map +1 -1
  33. package/lib/typescript/src/GlobalErrorHandler.d.ts.map +1 -1
  34. package/lib/typescript/src/MappIntelligencePlugin.d.ts +201 -0
  35. package/lib/typescript/src/MappIntelligencePlugin.d.ts.map +1 -0
  36. package/lib/typescript/src/UseWebTracking.d.ts.map +1 -1
  37. package/lib/typescript/src/index.d.ts +2 -200
  38. package/lib/typescript/src/index.d.ts.map +1 -1
  39. package/mapp-intelligence-reactnative-plugin.podspec +1 -1
  40. package/package.json +27 -22
  41. package/src/Converters.tsx +1 -1
  42. package/src/GlobalErrorHandler.tsx +3 -6
  43. package/src/MappIntelligencePlugin.tsx +392 -0
  44. package/src/UseWebTracking.tsx +13 -27
  45. package/src/index.tsx +2 -410
@@ -0,0 +1,392 @@
1
+ import { Platform, NativeModules } from 'react-native';
2
+ import {
3
+ convertPageParameters,
4
+ convertSessionParamters,
5
+ convertUserCategories,
6
+ convertEcommerceParameters,
7
+ convertCampaignParameters,
8
+ convertEventParameters,
9
+ convertMediaEvent,
10
+ } from './Converters';
11
+ import type {
12
+ LogLevel,
13
+ ExceptionType,
14
+ PageParameters,
15
+ SessionParameters,
16
+ UserCategories,
17
+ EcommerceParameters,
18
+ CampaignParameters,
19
+ EventParameters,
20
+ MediaEvent,
21
+ } from './DataTypes';
22
+
23
+ const LINKING_ERROR =
24
+ `The package 'mapp-intelligence-reactnative-plugin' doesn't seem to be linked. Make sure: \n\n` +
25
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
26
+ '- You rebuilt the app after installing the package\n' +
27
+ '- You are not using Expo Go\n';
28
+
29
+ const mappPlugin = NativeModules.MappinteligencePlugin
30
+ ? NativeModules.MappinteligencePlugin
31
+ : new Proxy(
32
+ {},
33
+ {
34
+ get() {
35
+ throw new Error(LINKING_ERROR);
36
+ },
37
+ }
38
+ );
39
+
40
+ export const MappIntelligencePlugin = {
41
+ /**
42
+ * Builds plugin with a provided configuration. After this method finishes, plugin is ready for use.
43
+ * @returns result if method executed succesfully or not
44
+ */
45
+ build: (): Promise<number> => {
46
+ console.log('build');
47
+ return mappPlugin.build();
48
+ },
49
+
50
+ /**
51
+ * Initialize plugin with a provided trackIds and domain
52
+ * @param trackIDs array of trackIds
53
+ * @param domain tracking domain url
54
+ * @returns result if method executed succesfully or not
55
+ */
56
+ initWithConfiguration: (
57
+ trackIDs: number[],
58
+ domain: string
59
+ ): Promise<number> => {
60
+ console.log('initWithConfiguration');
61
+ return mappPlugin.initWithConfiguration(trackIDs, domain);
62
+ },
63
+
64
+ /**
65
+ * Set log level to define what will be logged to the console
66
+ * @param level log level
67
+ * @returns result if method executed succesfully or not
68
+ */
69
+ setLogLevel: (level: LogLevel): Promise<number> => {
70
+ console.log('setLogLevel - ' + level.valueOf());
71
+ return mappPlugin.setLogLevel(level.valueOf());
72
+ },
73
+
74
+ /**
75
+ * Set exception log level
76
+ * @param level one of the predefined exception types
77
+ * @returns result if method executed succesfully or not
78
+ */
79
+ setExceptionLogLevel: (level: ExceptionType): Promise<number> => {
80
+ return mappPlugin.setExceptionLogLevel(level);
81
+ },
82
+
83
+ /**
84
+ * Sets interval in minutes, for periodic job to execute and send tracked requests to a server
85
+ * @param interval number in minutes. The minimum is 15, limited by Android specification for a worker.
86
+ * @returns result if method executed succesfully or not
87
+ */
88
+ setRequestInterval: (interval: number): Promise<number> => {
89
+ console.log('setRequestInterval');
90
+ return mappPlugin.setRequestInterval(interval);
91
+ },
92
+
93
+ /**
94
+ * If sets to true, request will be send in a batch (multiple records in single network call);
95
+ * Otherwise records are sent one record by one network call.
96
+ * @param enabled speciffy if batch is enabled or disabled
97
+ * @returns result if method executed succesfully or not
98
+ */
99
+ setBatchSupportEnabled: (enabled: boolean): Promise<number> => {
100
+ console.log('setBatchSupportEnabled');
101
+ return mappPlugin.setBatchSupportEnabled(enabled);
102
+ },
103
+
104
+ /**
105
+ * iOS Only - Enable sending data while application is in a background state
106
+ * @param enabled
107
+ * @returns result if method executed succesfully or not
108
+ */
109
+ setEnableBackgroundSendout: (enabled: boolean): Promise<number> => {
110
+ console.log('setEnableBackgroundSendout');
111
+ return mappPlugin.setEnableBackgroundSendout(enabled);
112
+ },
113
+
114
+ /**
115
+ * Set number of track records to send in a sigle batch request
116
+ * @param size number of track records
117
+ * @returns result if method executed succesfully or not
118
+ */
119
+ setBatchSupportSize: (size: number): Promise<number> => {
120
+ console.log('setBatchSupportSize');
121
+ return mappPlugin.setBatchSupportSize(size);
122
+ },
123
+
124
+ /**
125
+ * Requests are buffered in a queue before sending. This option set size of the queue.
126
+ * @param numberOfRequsts size of a queue for buffering requests
127
+ * @returns result if method executed succesfully or not
128
+ */
129
+ setRequestPerQueue: (numberOfRequsts: number): Promise<number> => {
130
+ console.log('setRequestPerQueue');
131
+ return mappPlugin.setRequestPerQueue(numberOfRequsts);
132
+ },
133
+
134
+ /**
135
+ * Control if migration should be applied from a previos SDK version.
136
+ * @param migrate true to apply migration on the initialization process; otherwise false
137
+ * @returns result if method executed succesfully or not
138
+ */
139
+ setShouldMigrate: (migrate: boolean): Promise<number> => {
140
+ console.log('setShouldMigrate');
141
+ return mappPlugin.setShouldMigrate(migrate);
142
+ },
143
+
144
+ /**
145
+ * Based on the result of the user's conset to allow personalized tracking or not,
146
+ * enable anonymous tracking when no consent. If enabled, everId will be deleted (and not generated until anonymous tracking is enabled)
147
+ * @param anonymous true to enable anonymous tracking; false to disable it.
148
+ * @returns result if method executed succesfully or not
149
+ */
150
+ setAnonymousTracking: (anonymous: boolean): Promise<number> => {
151
+ console.log('setAnonymousTracking');
152
+ return mappPlugin.setAnonymousTracking(anonymous);
153
+ },
154
+
155
+ /**
156
+ * Send application version as parameter in every request
157
+ * @param flag - true to set sending application version in every request; otherwise false.
158
+ * @returns result if method executed succesfully or not
159
+ */
160
+ setSendAppVersionInEveryRequest: (flag: boolean): Promise<number> => {
161
+ console.log('setSendAppVersionInEveryRequest');
162
+ return mappPlugin.setSendAppVersionInEveryRequest(flag);
163
+ },
164
+
165
+ /**
166
+ * To enable user matching between Engage and Intelligence system
167
+ * @param enabled true to enable user matching; false to disable it.
168
+ * @returns result if method executed succesfully or not
169
+ */
170
+ setEnableUserMatching: (enabled: boolean): Promise<number> => {
171
+ console.log('setEnableUserMatching');
172
+ return mappPlugin.setEnableUserMatching(enabled);
173
+ },
174
+
175
+ /**
176
+ * Track single page by page name
177
+ * @param pageTitle page name for tracking
178
+ * @returns result if method executed succesfully or not
179
+ */
180
+ trackPage: (pageTitle: string): Promise<number> => {
181
+ console.log('trackPage');
182
+ return mappPlugin.trackPage(pageTitle);
183
+ },
184
+
185
+ /**
186
+ * Detailed page tracking with additional parameters that can be set to track
187
+ * @param pageTitle - name of the page
188
+ * @param pageParameters - parameters for the page
189
+ * @param sessionParamters - parameters for the current session
190
+ * @param userCategories - predefined user categories
191
+ * @param ecommerceParameters - predefined eCommerce parameters
192
+ * @param campaignParameters - predefined campaign parameters
193
+ * @returns result if method executed succesfully or not
194
+ */
195
+ trackCustomPage: (
196
+ pageTitle: string,
197
+ pageParameters?: PageParameters | null,
198
+ sessionParamters?: SessionParameters | null,
199
+ userCategories?: UserCategories | null,
200
+ ecommerceParameters?: EcommerceParameters | null,
201
+ campaignParameters?: CampaignParameters | null
202
+ ): Promise<number> => {
203
+ console.log('trackCustomPage');
204
+ return mappPlugin.trackCustomPage(
205
+ pageTitle,
206
+ convertPageParameters(pageParameters),
207
+ convertSessionParamters(sessionParamters),
208
+ convertUserCategories(userCategories),
209
+ convertEcommerceParameters(ecommerceParameters),
210
+ convertCampaignParameters(campaignParameters)
211
+ );
212
+ },
213
+
214
+ /**
215
+ * Custom page tracking with option to track some custom parameters
216
+ * @param pageTitle - name of the page
217
+ * @param pageParameters - custom parameters that can be tracked
218
+ * @returns result if method executed succesfully or not
219
+ */
220
+ trackPageWithCustomData: (
221
+ pageTitle: string,
222
+ pageParameters: Map<string, string> | null
223
+ ): Promise<number> => {
224
+ console.log('trackPageWithCustomData', pageParameters);
225
+ return mappPlugin.trackPageWithCustomData(pageParameters, pageTitle);
226
+ },
227
+
228
+ /**
229
+ * Track user action
230
+ * @param name - action name
231
+ * @param eventParameters - predefined event parameters
232
+ * @param sessionParamters - predefined session parameters
233
+ * @param userCategories - predefined user categories
234
+ * @param ecommerceParameters - predefined ecommerce parameters
235
+ * @param campaignParameters - predefined campaign parameters
236
+ * @returns result if method executed succesfully or not
237
+ */
238
+ trackAction: (
239
+ name: string,
240
+ eventParameters?: EventParameters | null,
241
+ sessionParamters?: SessionParameters | null,
242
+ userCategories?: UserCategories | null,
243
+ ecommerceParameters?: EcommerceParameters | null,
244
+ campaignParameters?: CampaignParameters | null
245
+ ): Promise<number> => {
246
+ console.log('trackAction');
247
+ return mappPlugin.trackAction(
248
+ name,
249
+ convertEventParameters(eventParameters),
250
+ convertSessionParamters(sessionParamters),
251
+ convertUserCategories(userCategories),
252
+ convertEcommerceParameters(ecommerceParameters),
253
+ convertCampaignParameters(campaignParameters)
254
+ );
255
+ },
256
+
257
+ /**
258
+ * Track URL's with included deeplinks, media parameters
259
+ * @param url single url that can contain some query parameters for tracking
260
+ * @param mediaCode media code to track
261
+ * @returns result if method executed succesfully or not
262
+ */
263
+ trackUrl: (url: string, mediaCode?: string | null): Promise<number> => {
264
+ return mappPlugin.trackUrl(url, mediaCode);
265
+ },
266
+
267
+ /**
268
+ * Track video or audio events - starting, playing, pausing/stoping, ending of playing
269
+ * @param mediaEvent predefined events to track
270
+ * @returns result if method executed succesfully or not
271
+ */
272
+ trackMedia: (mediaEvent: MediaEvent): Promise<number> => {
273
+ console.log('Execute MediaEvent');
274
+ return mappPlugin.trackMedia(convertMediaEvent(mediaEvent as MediaEvent));
275
+ },
276
+
277
+ /**
278
+ * Record data about handled exceptions
279
+ * @param e caught exception
280
+ * @param stackTrace stack trace of the caught exception
281
+ * @returns result if method executed succesfully or not
282
+ */
283
+ trackException: (e: Error, stackTrace?: string | null): Promise<number> => {
284
+ return mappPlugin.trackException(
285
+ e.name,
286
+ e.message?.slice(0, 1000),
287
+ stackTrace?.slice(0, 1000)
288
+ );
289
+ },
290
+
291
+ /**
292
+ * Record data about handled exception
293
+ * @param name name or type of the exception if can be obtained
294
+ * @param message message of the current caught exception
295
+ * @param stackTrace stack trace of the caught exception
296
+ * @returns result if method executed succesfully or not
297
+ */
298
+ trackExceptionWithName: (
299
+ name: string,
300
+ message: string,
301
+ stackTrace?: string | null
302
+ ): Promise<number> => {
303
+ return mappPlugin.trackException(
304
+ name,
305
+ message.slice(0, 1000),
306
+ stackTrace?.slice(0, 1000)
307
+ );
308
+ },
309
+
310
+ /**
311
+ * Set unique everId as identifier for a single device/user
312
+ * @param everId unique identifier in the tracking system
313
+ * @returns result if method executed succesfully or not
314
+ */
315
+ setEverId: (everId?: String | null): Promise<number> => {
316
+ console.log('setEverId');
317
+ return mappPlugin.setEverId(everId);
318
+ },
319
+
320
+ /**
321
+ * Returns current everId of a device
322
+ * @returns everId
323
+ */
324
+ getEverId: (): Promise<string> => {
325
+ return mappPlugin.getEverId();
326
+ },
327
+
328
+ /**
329
+ * Check if plugin is initialized and ready to use
330
+ * @returns true if plugin is ready to use; false otherwise.
331
+ */
332
+ isInitialized: (): Promise<boolean> => {
333
+ return mappPlugin.isInitialized();
334
+ },
335
+
336
+ /**
337
+ * Temporary sessionId is used when anonymous tracking is enabled to provide
338
+ * anonymous tracking of a single session
339
+ * @param sessionId unique session identifier
340
+ * @returns result if method executed succesfully or not
341
+ */
342
+ setTemporarySessionId: (sessionId?: String | null): Promise<number> => {
343
+ console.log('setTemporarySessionId');
344
+ return mappPlugin.setTemporarySessionId(sessionId);
345
+ },
346
+
347
+ /**
348
+ * In some cases, it is necessary to exclude users completely from tracking.
349
+ * For this purpose, the SDK provides an opt-out option.
350
+ * Internally, calling this method will delete all current tracking data cached in the database (if sendCurrentData is set to false), cancel the sending of requests, terminate the WorkManager, and disable all incoming tracking requests.
351
+ * @param sendData true to send recorded data before opt-out
352
+ * @returns result if method executed succesfully or not
353
+ */
354
+ optOut: (sendData: boolean): Promise<number> => {
355
+ return mappPlugin.optOut(sendData);
356
+ },
357
+
358
+ /**
359
+ * Disables opt-out, and resets tracking to enabled.
360
+ * @param sendData true to send recorded data before opt-in
361
+ * @returns result if method executed succesfully or not
362
+ */
363
+ optIn: (sendData: boolean): Promise<number> => {
364
+ return mappPlugin.optIn(sendData);
365
+ },
366
+
367
+ /**
368
+ * Reset all webtrekk configuration. After this, new init with settings must be called before using plugin.
369
+ * @returns result if method executed succesfully or not
370
+ */
371
+ reset: (): Promise<number> => {
372
+ return mappPlugin.reset();
373
+ },
374
+
375
+ /**
376
+ * When called, data will be immediately sent.
377
+ * The request will then be deleted from the database, cleaning it.
378
+ * Please note that the application must be started and visible to use this method.
379
+ * @returns result if method executed succesfully or not
380
+ */
381
+ sendRequestsAndClean: (): Promise<number> => {
382
+ return mappPlugin.sendRequestsAndClean();
383
+ },
384
+
385
+ /**
386
+ * Get active configuration of the native SDK and returns it as a string
387
+ * @returns string representation of the active configuration
388
+ */
389
+ printCurrentConfig: (): Promise<string> => {
390
+ return mappPlugin.getCurrentConfig();
391
+ },
392
+ };
@@ -1,12 +1,5 @@
1
- // useWebTracking.tsx
1
+ import { MappIntelligencePlugin } from './MappIntelligencePlugin';
2
2
  import { useRef, useCallback } from 'react';
3
- import {
4
- trackPageWithCustomData,
5
- trackAction,
6
- trackException,
7
- getEverId,
8
- } from './index';
9
- //import * as MappIntelligencePlugin from 'mapp-intelligence-reactnative-plugin';
10
3
  import type { WebViewMessageEvent } from 'react-native-webview';
11
4
  import { WebView } from 'react-native-webview';
12
5
 
@@ -15,20 +8,6 @@ const runOnce = `
15
8
  meta.setAttribute('name', 'viewport');
16
9
  meta.setAttribute('content', 'width=device-width, height=device-height, initial-scale=0.85, maximum-scale=1.0, user-scalable=no');
17
10
  document.getElementsByTagName('head')[0].appendChild(meta);
18
-
19
- window.WebtrekkAndroidWebViewCallback = {};
20
-
21
- window.WebtrekkAndroidWebViewCallback.trackCustomPage = function(pageName,param){
22
- window.ReactNativeWebView.postMessage(JSON.stringify({ 'method': 'trackCustomPage', 'name':pageName, 'params':param }));
23
- }
24
-
25
- window.WebtrekkAndroidWebViewCallback.trackCustomEvent = function(eventName, param){
26
- window.ReactNativeWebView.postMessage(JSON.stringify({ 'method': 'trackCustomEvent', 'name':eventName, 'params':param }));
27
- }
28
-
29
- window.WebtrekkAndroidWebViewCallback.getEverId = function(){
30
- window.ReactNativeWebView.postMessage(JSON.stringify({ 'method': 'getEverId', 'name':'webtrekkApplicationEverId', 'params': window.webtrekkApplicationEverId }));
31
- }
32
11
  `;
33
12
  const injectEverIdScript = `window.webtrekkApplicationEverId = '%everId%' ; true; `;
34
13
 
@@ -67,9 +46,9 @@ export const useWebTracking = (
67
46
 
68
47
  const trackCustomPage = (name: string, params: any) => {
69
48
  try {
70
- const parameters = getJson(params) ?? new Map();
49
+ const parameters = getJson(params);
71
50
  console.log('Page Name: ', name, '; Params: ', parameters);
72
- trackPageWithCustomData(name, parameters);
51
+ MappIntelligencePlugin.trackPageWithCustomData(name, parameters);
73
52
  } catch (error) {
74
53
  console.error(error);
75
54
  }
@@ -79,7 +58,14 @@ export const useWebTracking = (
79
58
  try {
80
59
  const parameters = getJson(params);
81
60
  console.log('Event Name: ', name, '; Params: ', parameters);
82
- trackAction(name, parameters, null, null, null, null);
61
+ MappIntelligencePlugin.trackAction(
62
+ name,
63
+ parameters,
64
+ null,
65
+ null,
66
+ null,
67
+ null
68
+ );
83
69
  } catch (error) {
84
70
  console.error(error);
85
71
  }
@@ -98,7 +84,7 @@ export const useWebTracking = (
98
84
  };
99
85
 
100
86
  const handleLoad = useCallback(() => {
101
- getEverId()
87
+ MappIntelligencePlugin.getEverId()
102
88
  .then((everId: string) => {
103
89
  if (webViewRef.current) {
104
90
  const scripts = injectEverIdScript.replace('%everId%', everId);
@@ -114,7 +100,7 @@ export const useWebTracking = (
114
100
  })
115
101
  .catch((error: Error) => {
116
102
  console.error(error);
117
- trackException(error);
103
+ MappIntelligencePlugin.trackException(error);
118
104
  });
119
105
 
120
106
  if (onLoad) {