mapp-intelligence-reactnative-plugin 1.0.0 → 1.0.2

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 (43) hide show
  1. package/README.md +31 -7
  2. package/android/gradle.properties +3 -3
  3. package/android/src/main/java/com/mappinteligenceplugin/mapper/Util.kt +12 -4
  4. package/lib/commonjs/Converters.js +1 -1
  5. package/lib/commonjs/Converters.js.map +1 -1
  6. package/lib/commonjs/GlobalErrorHandler.js +2 -6
  7. package/lib/commonjs/GlobalErrorHandler.js.map +1 -1
  8. package/lib/commonjs/MappIntelligencePlugin.js +298 -0
  9. package/lib/commonjs/MappIntelligencePlugin.js.map +1 -0
  10. package/lib/commonjs/UseWebTracking.js +7 -11
  11. package/lib/commonjs/UseWebTracking.js.map +1 -1
  12. package/lib/commonjs/index.js +49 -378
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/promiseRejectionHandler.js.map +1 -1
  15. package/lib/module/Converters.js +1 -1
  16. package/lib/module/Converters.js.map +1 -1
  17. package/lib/module/GlobalErrorHandler.js +2 -6
  18. package/lib/module/GlobalErrorHandler.js.map +1 -1
  19. package/lib/module/MappIntelligencePlugin.js +292 -0
  20. package/lib/module/MappIntelligencePlugin.js.map +1 -0
  21. package/lib/module/UseWebTracking.js +6 -10
  22. package/lib/module/UseWebTracking.js.map +1 -1
  23. package/lib/module/index.js +5 -319
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/module/promiseRejectionHandler.js.map +1 -1
  26. package/lib/typescript/src/Converters.d.ts +1 -1
  27. package/lib/typescript/src/Converters.d.ts.map +1 -1
  28. package/lib/typescript/src/DataTypes.d.ts +6 -6
  29. package/lib/typescript/src/DataTypes.d.ts.map +1 -1
  30. package/lib/typescript/src/GlobalErrorHandler.d.ts.map +1 -1
  31. package/lib/typescript/src/MappIntelligencePlugin.d.ts +201 -0
  32. package/lib/typescript/src/MappIntelligencePlugin.d.ts.map +1 -0
  33. package/lib/typescript/src/UseWebTracking.d.ts +2 -2
  34. package/lib/typescript/src/UseWebTracking.d.ts.map +1 -1
  35. package/lib/typescript/src/index.d.ts +5 -199
  36. package/lib/typescript/src/index.d.ts.map +1 -1
  37. package/mapp-intelligence-reactnative-plugin.podspec +1 -1
  38. package/package.json +28 -24
  39. package/src/Converters.tsx +6 -6
  40. package/src/GlobalErrorHandler.tsx +3 -6
  41. package/src/MappIntelligencePlugin.tsx +394 -0
  42. package/src/UseWebTracking.tsx +13 -15
  43. package/src/index.tsx +5 -409
@@ -0,0 +1,394 @@
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');
225
+ const params = pageParameters?.entries();
226
+ const data = params != null ? Object.fromEntries(params) : {};
227
+ return mappPlugin.trackPageWithCustomData(data, pageTitle);
228
+ },
229
+
230
+ /**
231
+ * Track user action
232
+ * @param name - action name
233
+ * @param eventParameters - predefined event parameters
234
+ * @param sessionParamters - predefined session parameters
235
+ * @param userCategories - predefined user categories
236
+ * @param ecommerceParameters - predefined ecommerce parameters
237
+ * @param campaignParameters - predefined campaign parameters
238
+ * @returns result if method executed succesfully or not
239
+ */
240
+ trackAction: (
241
+ name: string,
242
+ eventParameters?: EventParameters | null,
243
+ sessionParamters?: SessionParameters | null,
244
+ userCategories?: UserCategories | null,
245
+ ecommerceParameters?: EcommerceParameters | null,
246
+ campaignParameters?: CampaignParameters | null
247
+ ): Promise<number> => {
248
+ console.log('trackAction');
249
+ return mappPlugin.trackAction(
250
+ name,
251
+ convertEventParameters(eventParameters),
252
+ convertSessionParamters(sessionParamters),
253
+ convertUserCategories(userCategories),
254
+ convertEcommerceParameters(ecommerceParameters),
255
+ convertCampaignParameters(campaignParameters)
256
+ );
257
+ },
258
+
259
+ /**
260
+ * Track URL's with included deeplinks, media parameters
261
+ * @param url single url that can contain some query parameters for tracking
262
+ * @param mediaCode media code to track
263
+ * @returns result if method executed succesfully or not
264
+ */
265
+ trackUrl: (url: string, mediaCode?: string | null): Promise<number> => {
266
+ return mappPlugin.trackUrl(url, mediaCode);
267
+ },
268
+
269
+ /**
270
+ * Track video or audio events - starting, playing, pausing/stoping, ending of playing
271
+ * @param mediaEvent predefined events to track
272
+ * @returns result if method executed succesfully or not
273
+ */
274
+ trackMedia: (mediaEvent: MediaEvent): Promise<number> => {
275
+ console.log('Execute MediaEvent');
276
+ return mappPlugin.trackMedia(convertMediaEvent(mediaEvent as MediaEvent));
277
+ },
278
+
279
+ /**
280
+ * Record data about handled exceptions
281
+ * @param e caught exception
282
+ * @param stackTrace stack trace of the caught exception
283
+ * @returns result if method executed succesfully or not
284
+ */
285
+ trackException: (e: Error, stackTrace?: string | null): Promise<number> => {
286
+ return mappPlugin.trackException(
287
+ e.name,
288
+ e.message?.slice(0, 1000),
289
+ stackTrace?.slice(0, 1000)
290
+ );
291
+ },
292
+
293
+ /**
294
+ * Record data about handled exception
295
+ * @param name name or type of the exception if can be obtained
296
+ * @param message message of the current caught exception
297
+ * @param stackTrace stack trace of the caught exception
298
+ * @returns result if method executed succesfully or not
299
+ */
300
+ trackExceptionWithName: (
301
+ name: string,
302
+ message: string,
303
+ stackTrace?: string | null
304
+ ): Promise<number> => {
305
+ return mappPlugin.trackException(
306
+ name,
307
+ message.slice(0, 1000),
308
+ stackTrace?.slice(0, 1000)
309
+ );
310
+ },
311
+
312
+ /**
313
+ * Set unique everId as identifier for a single device/user
314
+ * @param everId unique identifier in the tracking system
315
+ * @returns result if method executed succesfully or not
316
+ */
317
+ setEverId: (everId?: String | null): Promise<number> => {
318
+ console.log('setEverId');
319
+ return mappPlugin.setEverId(everId);
320
+ },
321
+
322
+ /**
323
+ * Returns current everId of a device
324
+ * @returns everId
325
+ */
326
+ getEverId: (): Promise<string> => {
327
+ return mappPlugin.getEverId();
328
+ },
329
+
330
+ /**
331
+ * Check if plugin is initialized and ready to use
332
+ * @returns true if plugin is ready to use; false otherwise.
333
+ */
334
+ isInitialized: (): Promise<boolean> => {
335
+ return mappPlugin.isInitialized();
336
+ },
337
+
338
+ /**
339
+ * Temporary sessionId is used when anonymous tracking is enabled to provide
340
+ * anonymous tracking of a single session
341
+ * @param sessionId unique session identifier
342
+ * @returns result if method executed succesfully or not
343
+ */
344
+ setTemporarySessionId: (sessionId?: String | null): Promise<number> => {
345
+ console.log('setTemporarySessionId');
346
+ return mappPlugin.setTemporarySessionId(sessionId);
347
+ },
348
+
349
+ /**
350
+ * In some cases, it is necessary to exclude users completely from tracking.
351
+ * For this purpose, the SDK provides an opt-out option.
352
+ * 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.
353
+ * @param sendData true to send recorded data before opt-out
354
+ * @returns result if method executed succesfully or not
355
+ */
356
+ optOut: (sendData: boolean): Promise<number> => {
357
+ return mappPlugin.optOut(sendData);
358
+ },
359
+
360
+ /**
361
+ * Disables opt-out, and resets tracking to enabled.
362
+ * @param sendData true to send recorded data before opt-in
363
+ * @returns result if method executed succesfully or not
364
+ */
365
+ optIn: (sendData: boolean): Promise<number> => {
366
+ return mappPlugin.optIn(sendData);
367
+ },
368
+
369
+ /**
370
+ * Reset all webtrekk configuration. After this, new init with settings must be called before using plugin.
371
+ * @returns result if method executed succesfully or not
372
+ */
373
+ reset: (): Promise<number> => {
374
+ return mappPlugin.reset();
375
+ },
376
+
377
+ /**
378
+ * When called, data will be immediately sent.
379
+ * The request will then be deleted from the database, cleaning it.
380
+ * Please note that the application must be started and visible to use this method.
381
+ * @returns result if method executed succesfully or not
382
+ */
383
+ sendRequestsAndClean: (): Promise<number> => {
384
+ return mappPlugin.sendRequestsAndClean();
385
+ },
386
+
387
+ /**
388
+ * Get active configuration of the native SDK and returns it as a string
389
+ * @returns string representation of the active configuration
390
+ */
391
+ printCurrentConfig: (): Promise<string> => {
392
+ return mappPlugin.getCurrentConfig();
393
+ },
394
+ };
@@ -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 'react-native-mappinteligence-plugin';
10
3
  import type { WebViewMessageEvent } from 'react-native-webview';
11
4
  import { WebView } from 'react-native-webview';
12
5
 
@@ -36,7 +29,7 @@ type OnMessage = (data: any) => void;
36
29
 
37
30
  type OnLoad = () => void;
38
31
 
39
- const useWebTracking = (
32
+ export const useWebTracking = (
40
33
  onMessage?: OnMessage | null,
41
34
  onLoad?: OnLoad | null
42
35
  ) => {
@@ -69,7 +62,7 @@ const useWebTracking = (
69
62
  try {
70
63
  const parameters = getJson(params) ?? new Map();
71
64
  console.log('Page Name: ', name, '; Params: ', parameters);
72
- trackPageWithCustomData(name, parameters);
65
+ MappIntelligencePlugin.trackPageWithCustomData(name, parameters);
73
66
  } catch (error) {
74
67
  console.error(error);
75
68
  }
@@ -79,7 +72,14 @@ const useWebTracking = (
79
72
  try {
80
73
  const parameters = getJson(params);
81
74
  console.log('Event Name: ', name, '; Params: ', parameters);
82
- trackAction(name, parameters, null, null, null, null);
75
+ MappIntelligencePlugin.trackAction(
76
+ name,
77
+ parameters,
78
+ null,
79
+ null,
80
+ null,
81
+ null
82
+ );
83
83
  } catch (error) {
84
84
  console.error(error);
85
85
  }
@@ -98,7 +98,7 @@ const useWebTracking = (
98
98
  };
99
99
 
100
100
  const handleLoad = useCallback(() => {
101
- getEverId()
101
+ MappIntelligencePlugin.getEverId()
102
102
  .then((everId: string) => {
103
103
  if (webViewRef.current) {
104
104
  const scripts = injectEverIdScript.replace('%everId%', everId);
@@ -114,7 +114,7 @@ const useWebTracking = (
114
114
  })
115
115
  .catch((error: Error) => {
116
116
  console.error(error);
117
- trackException(error);
117
+ MappIntelligencePlugin.trackException(error);
118
118
  });
119
119
 
120
120
  if (onLoad) {
@@ -131,5 +131,3 @@ const useWebTracking = (
131
131
 
132
132
  return { webViewRef, handleMessage, handleLoad, getInjectedJavaScript };
133
133
  };
134
-
135
- export default useWebTracking;