@convivainc/conviva-react-native-appanalytics 0.1.2 → 0.1.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
 
2
2
  # Changelog
3
+
4
+ ## 0.1.5 (07/JUN/2024)
5
+ - Supports trackCustomEvent with JSONObject argument for [iOS Bridge](https://github.com/Conviva/conviva-ios-appanalytics)
6
+
7
+ ## 0.1.4 (05/JAN/2024)
8
+ - Supports the Auto Detection of ScreenView navigation if the application uses the [NavigationContainer](https://reactnavigation.org/docs/5.x/hello-react-navigation)(for react native version 5 and above) or [AppNavigator](https://reactnavigation.org/docs/4.x/hello-react-navigation)(for react native version below 5)<br>
9
+ *Note:Please refer to [ScreenView Auto-Detection](https://github.com/Conviva/conviva-react-native-appanalytics?tab=readme-ov-file#auto-detect-screenview-events-for-tracking-screen-navigation) for more details*
10
+
11
+ ## 0.1.3 (12/DEC/2023)
12
+ * Supports the Auto Detection of "buttonText" style for the User Click of Button, TouchableHighlight, TouchableOpacity, TouchableWithoutFeedback and TouchableNativeFeedback Components<br>
13
+ *This feature needs the Android App SDK version of [0.8.0](https://github.com/Conviva/conviva-android-appanalytics)*
14
+
3
15
  ## 0.1.2 (01/MAY/2023)
4
16
  * Supports the inclusion of the latest Android/iOS Native sensor always in the Android/iOS Bridge going forward
5
17
  * Fixes the issue of App Name being incorrect for iOS Bridge
@@ -13,4 +25,4 @@
13
25
  * Fixes the issue of optional Network Config argument being mandatory
14
26
 
15
27
  ## 0.0.1 (02/APR/2023)
16
- * Initial version of the Conviva React Native Sensor
28
+ * Initial version of the Conviva React Native Sensor
package/README.md CHANGED
@@ -10,7 +10,7 @@ npm install @convivainc/conviva-react-native-appanalytics --save
10
10
  npx pod-install
11
11
  ```
12
12
 
13
- ## Android Gradle dependency
13
+ ## Android Native Sensor dependencies
14
14
  Add the following line to app's build.gradle file along with the dependencies:
15
15
  ```
16
16
  dependencies {
@@ -18,6 +18,28 @@ dependencies {
18
18
  implementation 'com.conviva.sdk:conviva-android-tracker:<version>'
19
19
  }
20
20
  ```
21
+ Android Plugin should be used for the auto collection of **Button Click** and **OkHttp/Retrofit/HTTPSUrlConnection/HTTPUrlConnection** **NetworkRequest Tracking** features. The following example shows how to include the plugin:
22
+ ```
23
+ // in the root or project-level build.gradle
24
+ dependencies {
25
+ ...
26
+ // For Android Gradle Plugin version 8.0 and above, use
27
+ classpath 'com.conviva.sdk:android-plugin:0.3.x'
28
+
29
+ // For Android Gradle Plugin version below 8.0, use
30
+ classpath 'com.conviva.sdk:android-plugin:0.2.x'
31
+ ...
32
+ }
33
+
34
+ // in the app, build.gradle at the end of plugins add the
35
+ ...
36
+ apply plugin: 'com.conviva.sdk.android-plugin'
37
+
38
+ // in the app, build.gradle.kts at the end of plugins add the
39
+ plugins {
40
+ id 'com.conviva.sdk.android-plugin'
41
+ }
42
+ ```
21
43
 
22
44
  ## Initialize the tracker
23
45
  ```js
@@ -45,22 +67,80 @@ tracker.setSubjectData({userId: viewerId});
45
67
 
46
68
  ## Report PageView Events for tracking in-app page navigations.
47
69
  ```js
48
- tracker.trackPageViewEvent({pageUrl: string, pageTitle?: string, referrer?: string});
70
+ tracker.trackPageView({pageUrl: string, pageTitle?: string, referrer?: string});
49
71
 
50
72
  let pageViewEvent = {'pageUrl' : 'https://allpopulated.com',
51
73
  'pageTitle' : 'some title',
52
74
  'referrer' : 'http://refr.com'};
53
- tracker.trackPageViewEvent(pageViewEvent);
75
+ tracker.trackPageView(pageViewEvent);
76
+ ```
77
+
78
+ ## Auto detect button clicks.
79
+ Even though the React Native components can be natively mapped in Android and iOS, for the Auto detection of button clicks for **Button**, **TouchableHighlight**, **TouchableOpacity**, **TouchableWithoutFeedback** and **TouchableNativeFeedback** Components, needs explicit addition of babel transfomation. Add below plugin code in your application .babel.rc or babel.config.js file:
80
+
81
+ ```js
82
+
83
+ "plugins": ["./node_modules/@convivainc/conviva-react-native-appanalytics/instrumentation/index.js"]
84
+
85
+ ```
86
+
87
+ ## Auto detect ScreenView Events for tracking screen navigation.
88
+ To support Conviva to Auto Detect the Screen Name part of the ScreenView Events, add below plugin code in your application .babel.rc or babel.config.js file:
89
+ ```js
90
+
91
+ "plugins": ["add-react-displayname"]
92
+
93
+ ```
94
+
95
+ For React Navigation versions 5 and above, to autocapture screenviews, wrap withReactNavigationAutotrack(autocaptureNavigationTrack) around the NavigationContainer:
96
+
97
+ ```js
98
+
99
+ import {
100
+ withReactNavigationAutotrack,
101
+ autocaptureNavigationTrack
102
+ } from '@convivainc/conviva-react-native-appanalytics';
103
+
104
+
105
+ const ConvivaNavigationContainer =
106
+ withReactNavigationAutotrack(autocaptureNavigationTrack)(NavigationContainer);
107
+
108
+
109
+ <ConvivaNavigationContainer>
110
+ <Tab.Navigator>
111
+ <Tab.Screen name="Home" component={HomeScreen} />
112
+ <Tab.Screen name="Settings" component={SettingsScreen}/>
113
+ </Tab.Navigator>
114
+ </ConvivaNavigationContainer>
54
115
  ```
55
116
 
117
+ For React Navigation versions below 5, wrap the AppContainer (the result of a call to React Navigation’s createAppContainer() method) with withReactNavigationAutotrack(autocaptureNavigationTrack)
118
+ ```js
119
+
120
+ let AppNavigator = createStackNavigator(
121
+ {
122
+ Home: { screen: HomeScreen },
123
+ Settings: { screen: SettingsScreen }
124
+ },
125
+ {
126
+ initialRouteName: 'HomeScreen'
127
+ }
128
+ )
129
+
130
+ let App = withReactNavigationAutotrack(autocaptureNavigationTrack)(AppNavigator);
131
+
132
+ ```
133
+
134
+
56
135
  ## Custom event tracking to track your application specific events and state changes
136
+ <strong>_*** Note: Supported only in Android right now ***_<br></strong><br>
57
137
  Use trackCustomEvent() API to track all kinds of events. This API provides 2 fields to describe the tracked events.
58
138
 
59
139
  eventName - Name of the custom event. (Mandatory)
60
140
 
61
141
  eventData - Any JSON Object.
62
142
 
63
- The following example shows the implementation of the 'onClick' event listener to any element.
143
+ The following example shows the implementation of the application using these API's:
64
144
  ```js
65
145
  tracker.trackCustomEvent(eventName: string, eventData?: any);
66
146
 
@@ -74,7 +154,7 @@ Use setCustomTags() API to set all kinds of tags (key value pairs). This API pro
74
154
 
75
155
  data - Any JSON Object.
76
156
 
77
- The following example shows the implementation of the 'onClick' event listener to any element.
157
+ The following example shows the implementation of the application using this API:
78
158
 
79
159
  ```js
80
160
  tracker.setCustomTags(customTagsToSet: any);
@@ -87,7 +167,7 @@ Use clearCustomTags() API to remove that are set prior. This API provides 1 argu
87
167
 
88
168
  keys - Array of strings representing tag keys.
89
169
 
90
- The following example shows the implementation of the 'onClick' event listener to any element.
170
+ The following example shows the implementation of the application using this API:
91
171
  ```js
92
172
  tracker.clearCustomTags(tagKeys: string[]);
93
173
 
@@ -97,7 +177,22 @@ tracker.clearCustomTags(customTagKeysToClear);
97
177
 
98
178
  Use clearAllCustomTags() API to remove all the custom tags that are set prior.
99
179
 
100
- The following example shows the implementation of the 'onClick' event listener to any element.
180
+ The following example shows the implementation of the application using this API:
101
181
  ```js
102
182
  tracker.clearAllCustomTags();
103
183
  ```
184
+
185
+ <details>
186
+ <summary><b>Auto-collected Events</b></summary>
187
+
188
+ ##### Conviva provides a rich set of application performance metrics with the help of autocollected app events, such as _screen_view_ , _button_click_, and _network_request_.
189
+
190
+ Event | Occurrence |
191
+ ------|------------ |
192
+ network_request | after receiving the network request response ; auto collected from the Native Sensors, Need android-plugin inclusion for Android|
193
+ screen_view | when the screen is interacted on either first launch or relaunch ; auto collected from the Native Sensors + React Native Screens; Need add-react-displayname plugin and wrapping of Navigation Components |
194
+ application_error | when an error occurrs in the application ; auto collected from the Native Sensors|
195
+ button_click | on the button click callback ; auto collected from the Native Sensors + React Native **Button**, **TouchableHighlight**, **TouchableOpacity**, **TouchableWithoutFeedback** and **TouchableNativeFeedback** Components; Need Conviva index.js from the node_modules folder|
196
+ application_background | when the application is taken to the background ; auto collected from the Native Sensors|
197
+ application_foreground | when the application is taken to the foreground ; auto collected from the Native Sensors|
198
+ application_install | when the application is launched for the first time after it's installed. (It's not the exact installed time.) |
@@ -20,5 +20,5 @@ Pod::Spec.new do |s|
20
20
  s.requires_arc = true
21
21
 
22
22
  s.dependency "React-Core"
23
- s.dependency "ConvivaAppAnalytics", ">= 0.2.12"
23
+ s.dependency "ConvivaAppAnalytics", ">= 0.2.18"
24
24
  end
@@ -16,12 +16,12 @@ buildscript {
16
16
  apply plugin: "com.android.library"
17
17
 
18
18
  android {
19
- compileSdkVersion safeExtGet('compileSdkVersion', 30)
20
- buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
19
+ compileSdkVersion safeExtGet('compileSdkVersion', 33)
20
+ buildToolsVersion safeExtGet('buildToolsVersion', '30.0.2')
21
21
 
22
22
  defaultConfig {
23
23
  minSdkVersion safeExtGet('minSdkVersion', 21)
24
- targetSdkVersion safeExtGet('targetSdkVersion', 30)
24
+ targetSdkVersion safeExtGet('targetSdkVersion', 33)
25
25
  versionCode 1
26
26
  versionName "1.0"
27
27
  }
@@ -11,6 +11,7 @@ import com.conviva.apptracker.configuration.SessionConfiguration;
11
11
  import com.conviva.apptracker.configuration.SubjectConfiguration;
12
12
  import com.conviva.apptracker.configuration.TrackerConfiguration;
13
13
  import com.conviva.apptracker.controller.TrackerController;
14
+ import com.conviva.apptracker.event.ButtonClick;
14
15
  import com.conviva.apptracker.event.ConsentGranted;
15
16
  import com.conviva.apptracker.event.ConsentWithdrawn;
16
17
  import com.conviva.apptracker.event.DeepLinkReceived;
@@ -190,7 +191,8 @@ public class RNConvivaTrackerModule extends ReactContextBaseJavaModule {
190
191
  @ReactMethod
191
192
  public void removeAllTrackers(Promise promise) {
192
193
  try {
193
- ConvivaAppAnalytics.removeAllTrackers();
194
+ // commented out deprecated methods
195
+ // ConvivaAppAnalytics.removeAllTrackers();
194
196
  promise.resolve(true);
195
197
 
196
198
  } catch (Throwable t) {
@@ -488,14 +490,32 @@ public class RNConvivaTrackerModule extends ReactContextBaseJavaModule {
488
490
  }
489
491
 
490
492
  @ReactMethod
491
- public void removeGlobalContexts(ReadableMap details, Promise promise) {
493
+ public void trackClickEvent(ReadableMap details, Promise promise) {
492
494
  try {
493
495
  String namespace = details.getString("tracker");
494
- String tag = details.getString("removeTag");
495
-
496
+ ReadableMap eventMap = details.getMap("eventData");
496
497
  TrackerController trackerController = getTracker(namespace);
497
498
 
498
- trackerController.getGlobalContexts().remove(tag);
499
+ ButtonClick event = EventUtil.createButtonClickEvent(eventMap);
500
+ trackerController.track(event);
501
+
502
+ promise.resolve(true);
503
+
504
+ } catch (Throwable t) {
505
+ promise.reject("ERROR", t.getMessage());
506
+ }
507
+ }
508
+
509
+ @ReactMethod
510
+ public void removeGlobalContexts(ReadableMap details, Promise promise) {
511
+ try {
512
+ // commented out deprecated methods
513
+ // String namespace = details.getString("tracker");
514
+ // String tag = details.getString("removeTag");
515
+
516
+ // TrackerController trackerController = getTracker(namespace);
517
+
518
+ // trackerController.getGlobalContexts().remove(tag);
499
519
  promise.resolve(true);
500
520
 
501
521
  } catch (Throwable t) {
@@ -506,22 +526,23 @@ public class RNConvivaTrackerModule extends ReactContextBaseJavaModule {
506
526
  @ReactMethod
507
527
  public void addGlobalContexts(ReadableMap details, Promise promise) {
508
528
  try {
509
- String namespace = details.getString("tracker");
510
- ReadableMap gcArg = details.getMap("addGlobalContext");
529
+ // commented out deprecated methods
530
+ // String namespace = details.getString("tracker");
531
+ // ReadableMap gcArg = details.getMap("addGlobalContext");
511
532
 
512
- String tag = gcArg.getString("tag");
513
- ReadableArray globalContexts = gcArg.getArray("globalContexts");
533
+ // String tag = gcArg.getString("tag");
534
+ // ReadableArray globalContexts = gcArg.getArray("globalContexts");
514
535
 
515
- List<SelfDescribingJson> staticContexts = new ArrayList<>();
516
- for (int i = 0; i < globalContexts.size(); i++) {
517
- SelfDescribingJson gContext = EventUtil.createSelfDescribingJson(globalContexts.getMap(i));
518
- staticContexts.add(gContext);
519
- }
520
- GlobalContext gcStatic = new GlobalContext(staticContexts);
536
+ // List<SelfDescribingJson> staticContexts = new ArrayList<>();
537
+ // for (int i = 0; i < globalContexts.size(); i++) {
538
+ // SelfDescribingJson gContext = EventUtil.createSelfDescribingJson(globalContexts.getMap(i));
539
+ // staticContexts.add(gContext);
540
+ // }
541
+ // GlobalContext gcStatic = new GlobalContext(staticContexts);
521
542
 
522
- TrackerController trackerController = getTracker(namespace);
543
+ // TrackerController trackerController = getTracker(namespace);
523
544
 
524
- trackerController.getGlobalContexts().add(tag, gcStatic);
545
+ // trackerController.getGlobalContexts().add(tag, gcStatic);
525
546
  promise.resolve(true);
526
547
 
527
548
  } catch (Throwable t) {
@@ -722,11 +743,13 @@ public class RNConvivaTrackerModule extends ReactContextBaseJavaModule {
722
743
  @ReactMethod
723
744
  public void getSessionUserId(ReadableMap details, Promise promise) {
724
745
  try {
725
- String namespace = details.getString("tracker");
726
- TrackerController trackerController = getTracker(namespace);
746
+ // commented out deprecated methods
747
+ // String namespace = details.getString("tracker");
748
+ // TrackerController trackerController = getTracker(namespace);
727
749
 
728
- String suid = trackerController.getSession().getUserId();
729
- promise.resolve(suid);
750
+ // String suid = trackerController.getSession().getUserId();
751
+ // promise.resolve(suid);
752
+ promise.resolve(true);
730
753
  } catch (Throwable t) {
731
754
  promise.reject("ERROR", t.getMessage());
732
755
  }
@@ -735,11 +758,13 @@ public class RNConvivaTrackerModule extends ReactContextBaseJavaModule {
735
758
  @ReactMethod
736
759
  public void getSessionId(ReadableMap details, Promise promise) {
737
760
  try {
738
- String namespace = details.getString("tracker");
739
- TrackerController trackerController = getTracker(namespace);
761
+ // commented out deprecated methods
762
+ // String namespace = details.getString("tracker");
763
+ // TrackerController trackerController = getTracker(namespace);
740
764
 
741
- String sid = trackerController.getSession().getSessionId();
742
- promise.resolve(sid);
765
+ // String sid = trackerController.getSession().getSessionId();
766
+ // promise.resolve(sid);
767
+ promise.resolve(true);
743
768
  } catch (Throwable t) {
744
769
  promise.reject("ERROR", t.getMessage());
745
770
  }
@@ -748,11 +773,13 @@ public class RNConvivaTrackerModule extends ReactContextBaseJavaModule {
748
773
  @ReactMethod
749
774
  public void getSessionIndex(ReadableMap details, Promise promise) {
750
775
  try {
751
- String namespace = details.getString("tracker");
752
- TrackerController trackerController = getTracker(namespace);
776
+ // commented out deprecated methods
777
+ // String namespace = details.getString("tracker");
778
+ // TrackerController trackerController = getTracker(namespace);
753
779
 
754
- int sidx = trackerController.getSession().getSessionIndex();
755
- promise.resolve(sidx);
780
+ // int sidx = trackerController.getSession().getSessionIndex();
781
+ // promise.resolve(sidx);
782
+ promise.resolve(true);
756
783
  } catch (Throwable t) {
757
784
  promise.reject("ERROR", t.getMessage());
758
785
  }
@@ -761,11 +788,13 @@ public class RNConvivaTrackerModule extends ReactContextBaseJavaModule {
761
788
  @ReactMethod
762
789
  public void getIsInBackground(ReadableMap details, Promise promise) {
763
790
  try {
764
- String namespace = details.getString("tracker");
765
- TrackerController trackerController = getTracker(namespace);
791
+ // commented out deprecated methods
792
+ // String namespace = details.getString("tracker");
793
+ // TrackerController trackerController = getTracker(namespace);
766
794
 
767
- boolean isInBg = trackerController.getSession().isInBackground();
768
- promise.resolve(isInBg);
795
+ // boolean isInBg = trackerController.getSession().isInBackground();
796
+ // promise.resolve(isInBg);
797
+ promise.resolve(true);
769
798
  } catch (Throwable t) {
770
799
  promise.reject("ERROR", t.getMessage());
771
800
  }
@@ -774,11 +803,13 @@ public class RNConvivaTrackerModule extends ReactContextBaseJavaModule {
774
803
  @ReactMethod
775
804
  public void getBackgroundIndex(ReadableMap details, Promise promise) {
776
805
  try {
777
- String namespace = details.getString("tracker");
778
- TrackerController trackerController = getTracker(namespace);
806
+ // commented out deprecated methods
807
+ // String namespace = details.getString("tracker");
808
+ // TrackerController trackerController = getTracker(namespace);
779
809
 
780
- int bgIdx = trackerController.getSession().getBackgroundIndex();
781
- promise.resolve(bgIdx);
810
+ // int bgIdx = trackerController.getSession().getBackgroundIndex();
811
+ // promise.resolve(bgIdx);
812
+ promise.resolve(true);
782
813
  } catch (Throwable t) {
783
814
  promise.reject("ERROR", t.getMessage());
784
815
  }
@@ -787,11 +818,13 @@ public class RNConvivaTrackerModule extends ReactContextBaseJavaModule {
787
818
  @ReactMethod
788
819
  public void getForegroundIndex(ReadableMap details, Promise promise) {
789
820
  try {
790
- String namespace = details.getString("tracker");
791
- TrackerController trackerController = getTracker(namespace);
821
+ // commented out deprecated methods
822
+ // String namespace = details.getString("tracker");
823
+ // TrackerController trackerController = getTracker(namespace);
792
824
 
793
- int fgIdx = trackerController.getSession().getForegroundIndex();
794
- promise.resolve(fgIdx);
825
+ // int fgIdx = trackerController.getSession().getForegroundIndex();
826
+ // promise.resolve(fgIdx);
827
+ promise.resolve(true);
795
828
  } catch (Throwable t) {
796
829
  promise.reject("ERROR", t.getMessage());
797
830
  }
@@ -2,6 +2,7 @@ package com.conviva.react.apptracker.util;
2
2
 
3
3
  import androidx.annotation.NonNull;
4
4
 
5
+ import com.conviva.apptracker.event.ButtonClick;
5
6
  import com.conviva.apptracker.event.ConsentGranted;
6
7
  import com.conviva.apptracker.event.ConsentWithdrawn;
7
8
  import com.conviva.apptracker.event.DeepLinkReceived;
@@ -336,4 +337,10 @@ public class EventUtil {
336
337
 
337
338
  return event;
338
339
  }
340
+
341
+ public static ButtonClick createButtonClickEvent(ReadableMap argmap) {
342
+ ButtonClick event = ButtonClick.buildClickEvent(argmap.toHashMap());
343
+ Objects.requireNonNull(event, "atleast one attribute should be available");
344
+ return event;
345
+ }
339
346
  }
@@ -4,6 +4,6 @@ import com.conviva.react.apptracker.BuildConfig;
4
4
 
5
5
  public class TrackerVersion {
6
6
 
7
- public final static String RN_CONVIVA_TRACKER_VERSION = "rn-0.1.2";
7
+ public final static String RN_CONVIVA_TRACKER_VERSION = "rn-0.1.5";
8
8
 
9
9
  }
@@ -1,3 +1,5 @@
1
+ import * as react from 'react';
2
+
1
3
  /**
2
4
  * HttpMethod type
3
5
  */
@@ -800,6 +802,12 @@ type ReactNativeTracker = {
800
802
  * @returns {Promise<number | undefined>}
801
803
  */
802
804
  readonly getForegroundIndex: () => Promise<number | undefined>;
805
+ /**
806
+ * Tracks a click event
807
+ *
808
+ * @param eventData - The user click event properties
809
+ */
810
+ readonly trackClickEvent: (eventData: any) => Promise<void>;
803
811
  };
804
812
 
805
813
  /**
@@ -817,6 +825,8 @@ declare function getWebViewCallback(): (message: {
817
825
  };
818
826
  }) => void;
819
827
 
828
+ declare function withReactNavigationAutotrack(track: any): (AppContainer: any) => React.ForwardRefExoticComponent<React.RefAttributes<any>>;
829
+
820
830
  /**
821
831
  * Creates a React Native Tracker object
822
832
  *
@@ -838,5 +848,11 @@ declare function removeTracker(trackerNamespace: string): Promise<boolean>;
838
848
  * @returns - A boolean promise
839
849
  */
840
850
  declare function removeAllTrackers(): Promise<boolean>;
851
+ declare const autocaptureNavigationTrack: (...args: any[]) => any;
852
+
853
+ declare const _default: {
854
+ convivaTouchableAutoTrack: (TouchableComponent: any) => react.ForwardRefExoticComponent<react.RefAttributes<any>>;
855
+ withReactNavigationAutotrack: (AppContainer: any) => react.ForwardRefExoticComponent<react.RefAttributes<any>>;
856
+ };
841
857
 
842
- export { Basis, BufferOption, ConsentDocument, ConsentGrantedProps, ConsentWithdrawnProps, DeepLinkReceivedProps, DevicePlatform, EcommerceItem, EcommerceTransactionProps, EmitterConfiguration, EventContext, GCConfiguration, GdprConfiguration, GlobalContext, HttpMethod, LogLevel, MessageNotificationProps, NetworkConfiguration, PageViewProps, ReactNativeTracker, ScreenSize, ScreenViewProps, SelfDescribing, SessionConfiguration, StructuredProps, SubjectConfiguration, TimingProps, TrackerConfiguration, TrackerControllerConfiguration, Trigger, createTracker, getWebViewCallback, removeAllTrackers, removeTracker };
858
+ export { Basis, BufferOption, ConsentDocument, ConsentGrantedProps, ConsentWithdrawnProps, DeepLinkReceivedProps, DevicePlatform, EcommerceItem, EcommerceTransactionProps, EmitterConfiguration, EventContext, GCConfiguration, GdprConfiguration, GlobalContext, HttpMethod, LogLevel, MessageNotificationProps, NetworkConfiguration, PageViewProps, ReactNativeTracker, ScreenSize, ScreenViewProps, SelfDescribing, SessionConfiguration, StructuredProps, SubjectConfiguration, TimingProps, TrackerConfiguration, TrackerControllerConfiguration, Trigger, autocaptureNavigationTrack, createTracker, _default as default, getWebViewCallback, removeAllTrackers, removeTracker, withReactNavigationAutotrack };
@@ -1,4 +1,8 @@
1
1
  import { NativeModules } from 'react-native';
2
+ import * as React from 'react';
3
+ import React__default from 'react';
4
+ import hoistNonReactStatic from 'hoist-non-react-statics';
5
+ import * as _ from 'lodash';
2
6
 
3
7
  /*
4
8
  * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
@@ -124,6 +128,7 @@ const logMessages = {
124
128
  deepLinkReq: 'deepLinkReceived event requires the url parameter to be set',
125
129
  messageNotificationReq: 'messageNotification event requires title, body, and trigger parameters to be set',
126
130
  trackCustomEvent: 'trackCustomEvent event requires name and data',
131
+ trackClickEvent: 'click event requires atleast one attribute',
127
132
  // custom tags contexts
128
133
  setCustomTags: 'setCustomTags requires tags',
129
134
  clearCustomTags: 'clearCustomTags requires tag keys',
@@ -761,7 +766,7 @@ function trackScreenViewEvent$1(namespace, argmap, contexts = []) {
761
766
  contexts: contexts
762
767
  }))
763
768
  .catch((error) => {
764
- throw new Error(`${logMessages.trackScreenView} ${error.message}`);
769
+ throw new Error(`Conviva ${logMessages.trackScreenView} ${error.message}`);
765
770
  });
766
771
  }
767
772
  /**
@@ -1025,6 +1030,22 @@ function clearAllCustomTags$1(namespace, contexts = []) {
1025
1030
  throw new Error(`${logMessages.clearAllCustomTags} ${error.message}`);
1026
1031
  });
1027
1032
  }
1033
+ /**
1034
+ * Track user click event
1035
+ *
1036
+ * @param namespace {string} - the tracker namespace
1037
+ * @param eventData {any}- the user click data
1038
+ * @returns {Promise}
1039
+ */
1040
+ function trackClickEvent$1(namespace, eventData) {
1041
+ return RNConvivaTracker.trackClickEvent({
1042
+ tracker: namespace,
1043
+ eventData: eventData
1044
+ })
1045
+ .catch((error) => {
1046
+ throw new Error(`${logMessages.trackClickEvent} ${error.message}`);
1047
+ });
1048
+ }
1028
1049
 
1029
1050
  /*
1030
1051
  * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
@@ -1656,6 +1677,17 @@ function getForegroundIndex(namespace) {
1656
1677
  .resolve(RNConvivaTracker.getForegroundIndex({ tracker: namespace }));
1657
1678
  };
1658
1679
  }
1680
+ /**
1681
+ * Returns a function to track click event.
1682
+ *
1683
+ * @param namespace {string} - The tracker namespace
1684
+ * @returns - A function to track click event
1685
+ */
1686
+ function trackClickEvent(namespace) {
1687
+ return function (eventData) {
1688
+ return trackClickEvent$1(namespace, eventData);
1689
+ };
1690
+ }
1659
1691
 
1660
1692
  /*
1661
1693
  * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
@@ -1727,6 +1759,304 @@ function getWebViewCallback() {
1727
1759
  };
1728
1760
  }
1729
1761
 
1762
+ const logError = (message, error, quiet = false) => {
1763
+ const logger = quiet ? console.log : console.warn;
1764
+ if (error instanceof Error) {
1765
+ // KLUDGE: These properties don't show up if you `console.warn` the error object directly.
1766
+ logger(message, {
1767
+ name: error.name,
1768
+ message: error.message,
1769
+ stack: error.stack,
1770
+ });
1771
+ }
1772
+ else {
1773
+ logger(message, {
1774
+ message: String(error),
1775
+ });
1776
+ }
1777
+ };
1778
+ const handleError = (fn, name = null, quiet = false) => {
1779
+ return (...args) => {
1780
+ try {
1781
+ return fn(...args);
1782
+ }
1783
+ catch (e) {
1784
+ logError(name ? `Conviva: ${name} failed with an error.` : 'Conviva SDK encountered an error while tracking.', e, quiet);
1785
+ }
1786
+ };
1787
+ };
1788
+
1789
+ const getComponentDisplayName = WrappedComponent => {
1790
+ return WrappedComponent.displayName || WrappedComponent.name || 'Component';
1791
+ };
1792
+
1793
+ const getCompTargetText = (comp) => {
1794
+ return getTargetText(getReactInternalFiber(comp));
1795
+ };
1796
+ const getReactInternalFiber = (comp) => {
1797
+ return comp._reactInternals || comp._reactInternalFiber || comp._fiber || comp._internalFiberInstanceHandleDEV;
1798
+ };
1799
+ const getTargetText = fiberNode => {
1800
+ if (fiberNode.type === 'RCTText') {
1801
+ return fiberNode.memoizedProps.children;
1802
+ }
1803
+ // In some cases, target text may not be within an 'RCTText' component. This has only been
1804
+ // observed in unit tests with Enzyme, but may still be a possibility in real RN apps.
1805
+ if (fiberNode.memoizedProps &&
1806
+ typeof fiberNode.memoizedProps.children === 'string') {
1807
+ return fiberNode.memoizedProps.children;
1808
+ }
1809
+ if (fiberNode.child === null) {
1810
+ return '';
1811
+ }
1812
+ const children = [];
1813
+ let currChild = fiberNode.child;
1814
+ while (currChild) {
1815
+ children.push(currChild);
1816
+ currChild = currChild.sibling;
1817
+ }
1818
+ let targetText = '';
1819
+ children.forEach(child => {
1820
+ targetText = (targetText + ' ' + getTargetText(child)).trim();
1821
+ });
1822
+ return targetText;
1823
+ };
1824
+
1825
+ var __rest = (undefined) || function (s, e) {
1826
+ var t = {};
1827
+ for (var p in s)
1828
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1829
+ t[p] = s[p];
1830
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
1831
+ for (var i = 0, q = Object.getOwnPropertySymbols(s); i < q.length; i++) {
1832
+ if (e.indexOf(q[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, q[i]))
1833
+ t[p[i]] = s[q[i]];
1834
+ }
1835
+ return t;
1836
+ };
1837
+ const convivaAutotrackPress = trackHandler => (_eventType, componentThis, _event) => {
1838
+ if (componentThis) {
1839
+ let data = { "elementId": componentThis.id, "elementClasses": componentThis.displayName, "elementType": componentThis.elementType, "elementText": getCompTargetText(componentThis) };
1840
+ // console.log("trackHandler data",data);
1841
+ trackHandler(data);
1842
+ }
1843
+ };
1844
+ const convivaTouchableAutoTrack = (track) => TouchableComponent => {
1845
+ class ConvivaTouchableAutoTrack extends React.Component {
1846
+ render() {
1847
+ const _a = this.props, { forwardedRef, onPress, onLongPress } = _a, rest = __rest(_a, ["forwardedRef", "onPress", "onLongPress"]);
1848
+ return (React.createElement(TouchableComponent, Object.assign({ ref: forwardedRef, onPress: e => {
1849
+ handleError(convivaAutotrackPress(track))('touchableHandlePress', this, e);
1850
+ onPress && onPress(e);
1851
+ }, onLongPress: e => {
1852
+ handleError(convivaAutotrackPress(track))('touchableHandleLongPress', this, e);
1853
+ onLongPress && onLongPress(e);
1854
+ } }, rest), this.props.children));
1855
+ }
1856
+ }
1857
+ ConvivaTouchableAutoTrack.displayName = `convivaTouchableAutoTrack(${getComponentDisplayName(TouchableComponent)})`;
1858
+ // console.log("ConvivaTouchableAutoTrack.displayName",ConvivaTouchableAutoTrack.displayName);
1859
+ const forwardRefHoc = React.forwardRef((props, ref) => {
1860
+ return React.createElement(ConvivaTouchableAutoTrack, Object.assign({}, props, { forwardedRef: ref }));
1861
+ });
1862
+ hoistNonReactStatic(forwardRefHoc, TouchableComponent);
1863
+ return forwardRefHoc;
1864
+ };
1865
+
1866
+ class DisplayNameTest {
1867
+ render() { }
1868
+ }
1869
+ let warningGiven = false;
1870
+ const checkDisplayNamePlugin = () => {
1871
+ // @ts-ignore
1872
+ if (!DisplayNameTest.displayName && !warningGiven) {
1873
+ console.warn('Conviva: Display names are not available');
1874
+ warningGiven = true;
1875
+ }
1876
+ };
1877
+
1878
+ class NavigationUtil {
1879
+ // :TODO: (jmtaber129): Add typing for this ref.
1880
+ static convivaNavRef;
1881
+ static setNavigationRef(ref) {
1882
+ this.convivaNavRef = ref;
1883
+ }
1884
+ static getScreenPropsForCurrentRoute() {
1885
+ let rootState = null;
1886
+ if (this.convivaNavRef && this.convivaNavRef.state && this.convivaNavRef.state.nav) {
1887
+ rootState = this.convivaNavRef.state.nav;
1888
+ }
1889
+ else if (this.convivaNavRef && this.convivaNavRef.getRootState) {
1890
+ rootState = this.convivaNavRef.getRootState();
1891
+ }
1892
+ if (rootState == null) {
1893
+ return null;
1894
+ }
1895
+ const routeProps = this.getActiveRouteProps(rootState);
1896
+ if (routeProps) {
1897
+ return routeProps;
1898
+ }
1899
+ return null;
1900
+ }
1901
+ static isHocEnabled() {
1902
+ return !!this.convivaNavRef;
1903
+ }
1904
+ // :TODO: (jmtaber129): Add type for navigationState.
1905
+ static getActiveRouteProps(navigationState) {
1906
+ const paths = this.getActiveRouteNames(navigationState);
1907
+ return {
1908
+ screen_path: paths.join('::'),
1909
+ screen_name: paths[paths.length - 1],
1910
+ };
1911
+ }
1912
+ // Returns an array of route names, with the root name first, and the most nested name last.
1913
+ static getActiveRouteNames(navigationState) {
1914
+ const route = navigationState.routes[navigationState.index];
1915
+ // Dive into nested navigators.
1916
+ let paths;
1917
+ if (route.routes) {
1918
+ paths = this.getActiveRouteNames(route);
1919
+ }
1920
+ else if (route.state && route.state.routes) {
1921
+ paths = this.getActiveRouteNames(route.state);
1922
+ }
1923
+ const routeName = route.routeName || route.name;
1924
+ if (paths) {
1925
+ return [routeName].concat(paths);
1926
+ }
1927
+ return [routeName];
1928
+ }
1929
+ }
1930
+
1931
+ const version = "0.22.6";
1932
+
1933
+ const { Platform } = require('react-native');
1934
+ let reactNativeVersionString = null;
1935
+ if (Platform && Platform.constants && Platform.constants.reactNativeVersion) {
1936
+ const { major, minor, patch } = Platform.constants.reactNativeVersion;
1937
+ reactNativeVersionString = `${major}.${minor}.${patch}`;
1938
+ }
1939
+ const getMetadataProps = () => {
1940
+ return {
1941
+ source_version: version,
1942
+ is_using_react_navigation_hoc: NavigationUtil.isHocEnabled(),
1943
+ react_native_version: reactNativeVersionString,
1944
+ };
1945
+ };
1946
+
1947
+ const getContextualProps = () => {
1948
+ return _.merge({}, getMetadataProps(), { name: NavigationUtil.getScreenPropsForCurrentRoute()?.screen_name
1949
+ // , id:NavigationUtil.getScreenPropsForCurrentRoute()?.screen_path
1950
+ });
1951
+ };
1952
+
1953
+ // const EVENT_TYPE = 'react_navigation_screenview';
1954
+ // const INITIAL_ROUTE_TYPE = 'Conviva_Navigation/INITIAL';
1955
+ const withReactNavigationAutotrack = track => AppContainer => {
1956
+ const wrapperObject = {};
1957
+ const existingWrapper = wrapperObject.__convivaWrapper;
1958
+ if (existingWrapper) {
1959
+ return existingWrapper;
1960
+ }
1961
+ const captureOldNavigationStateChange = handleError((prev, next) => {
1962
+ const { screen_path: prevScreenRoute } = NavigationUtil.getActiveRouteProps(prev);
1963
+ const { screen_path: nextScreenRoute } = NavigationUtil.getActiveRouteProps(next);
1964
+ if (prevScreenRoute !== nextScreenRoute) {
1965
+ track({
1966
+ ...getContextualProps(),
1967
+ });
1968
+ }
1969
+ }, 'Navigation event capture', true);
1970
+ class ConvivaNavigationWrapper extends React__default.Component {
1971
+ constructor(props) {
1972
+ super(props);
1973
+ this.topLevelNavigator = null;
1974
+ this.currentPath = null;
1975
+ }
1976
+ setRef(ref, value) {
1977
+ if (typeof ref === 'function') {
1978
+ ref(value);
1979
+ }
1980
+ else if (ref !== null) {
1981
+ ref.current = value;
1982
+ }
1983
+ }
1984
+ captureStateChange = handleError(state => {
1985
+ const { screen_path: nextPath } = NavigationUtil.getActiveRouteProps(state);
1986
+ if (nextPath !== this.currentPath) {
1987
+ track({
1988
+ previousName: this.currentPath || "",
1989
+ ...getContextualProps()
1990
+ });
1991
+ }
1992
+ this.currentPath = nextPath;
1993
+ }, 'Navigation event capture', true);
1994
+ captureOnReady = handleError(() => {
1995
+ if (this.topLevelNavigator.getRootState) {
1996
+ this.trackInitialRouteForState(this.topLevelNavigator.getRootState());
1997
+ const { screen_path: currentPath } = NavigationUtil.getActiveRouteProps(this.topLevelNavigator.getRootState());
1998
+ this.currentPath = currentPath;
1999
+ }
2000
+ }, 'Navigation event capture', true);
2001
+ trackInitialRouteForState(_) {
2002
+ // const { screen_path: initialPageviewPath } = NavigationUtil.getActiveRouteProps(navigationState);
2003
+ track({
2004
+ ...getContextualProps()
2005
+ });
2006
+ }
2007
+ render() {
2008
+ try {
2009
+ return this._render();
2010
+ }
2011
+ catch (e) {
2012
+ logError('Conviva: Failed to render React Navigation wrapper.', e);
2013
+ const { forwardedRef, ...rest } = this.props;
2014
+ return React__default.createElement(AppContainer, { ref: forwardedRef, ...rest });
2015
+ }
2016
+ }
2017
+ _render() {
2018
+ const { forwardedRef, onNavigationStateChange, onStateChange, onReady, ...rest } = this.props;
2019
+ return React__default.createElement(AppContainer, {
2020
+ ref: handleError((navigatorRef) => {
2021
+ this.setRef(forwardedRef, navigatorRef);
2022
+ NavigationUtil.setNavigationRef(navigatorRef);
2023
+ if (this.topLevelNavigator !== navigatorRef &&
2024
+ navigatorRef !== null) {
2025
+ this.topLevelNavigator = navigatorRef;
2026
+ if (this.topLevelNavigator.state) {
2027
+ this.trackInitialRouteForState(this.topLevelNavigator.state.nav);
2028
+ }
2029
+ }
2030
+ }, 'Navigation event capture', true),
2031
+ onReady: (...args) => {
2032
+ this.captureOnReady();
2033
+ if (typeof onReady === 'function') {
2034
+ onReady(...args);
2035
+ }
2036
+ },
2037
+ onStateChange: (...args) => {
2038
+ this.captureStateChange(...args);
2039
+ if (typeof onStateChange === 'function') {
2040
+ onStateChange(...args);
2041
+ }
2042
+ },
2043
+ onNavigationStateChange: (...args) => {
2044
+ captureOldNavigationStateChange(...args);
2045
+ if (typeof onNavigationStateChange === 'function') {
2046
+ onNavigationStateChange(...args);
2047
+ }
2048
+ },
2049
+ ...rest,
2050
+ }, this.props.children);
2051
+ }
2052
+ }
2053
+ ConvivaNavigationWrapper.displayName = `withReactNavigationAutotrack(${getComponentDisplayName(AppContainer)})`;
2054
+ wrapperObject.__convivaWrapper = React__default.forwardRef((props, ref) => {
2055
+ return React__default.createElement(ConvivaNavigationWrapper, { ...props, forwardedRef: ref });
2056
+ });
2057
+ return wrapperObject.__convivaWrapper;
2058
+ };
2059
+
1730
2060
  /*
1731
2061
  * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
1732
2062
  *
@@ -1772,6 +2102,7 @@ controllerConfig = {}) {
1772
2102
  const trackDeepLinkReceivedEvent$1 = mkMethod(trackDeepLinkReceivedEvent(namespace));
1773
2103
  const trackMessageNotificationEvent$1 = mkMethod(trackMessageNotificationEvent(namespace));
1774
2104
  const trackCustomEvent$1 = mkMethod(trackCustomEvent(namespace));
2105
+ const trackClickEvent$1 = mkMethod(trackClickEvent(namespace));
1775
2106
  // custom tags contexts
1776
2107
  const setCustomTags$1 = mkMethod(setCustomTags(namespace));
1777
2108
  const setCustomTagsWithCategory$1 = mkMethod(setCustomTagsWithCategory(namespace));
@@ -1834,6 +2165,7 @@ controllerConfig = {}) {
1834
2165
  getIsInBackground: getIsInBackground$1,
1835
2166
  getBackgroundIndex: getBackgroundIndex$1,
1836
2167
  getForegroundIndex: getForegroundIndex$1,
2168
+ trackClickEvent: trackClickEvent$1,
1837
2169
  });
1838
2170
  }
1839
2171
  /**
@@ -1855,6 +2187,18 @@ function removeAllTrackers() {
1855
2187
  return removeAllTrackers$1()
1856
2188
  .catch((e) => errorHandler(e));
1857
2189
  }
2190
+ const autocaptureNavigationTrack = handleError((payload) => {
2191
+ checkDisplayNamePlugin();
2192
+ trackScreenViewEvent('CAT')(payload).catch((e) => errorHandler(e));
2193
+ }, 'Event autocapture', true);
2194
+ const autocaptureTrack = handleError((payload) => {
2195
+ checkDisplayNamePlugin();
2196
+ trackClickEvent('CAT')(payload).catch((e) => errorHandler(e));
2197
+ }, 'Event autocapture', true);
2198
+ var index = {
2199
+ convivaTouchableAutoTrack: convivaTouchableAutoTrack(autocaptureTrack),
2200
+ withReactNavigationAutotrack: withReactNavigationAutotrack(autocaptureNavigationTrack)
2201
+ };
1858
2202
 
1859
- export { createTracker, getWebViewCallback, removeAllTrackers, removeTracker };
2203
+ export { autocaptureNavigationTrack, createTracker, index as default, getWebViewCallback, removeAllTrackers, removeTracker, withReactNavigationAutotrack };
1860
2204
  //# sourceMappingURL=conviva-react-native-appanalytics.js.map
@@ -0,0 +1,66 @@
1
+ const t = require('babel-types');
2
+ const template = require('babel-template');
3
+
4
+ const convivaLibImport = template(`(
5
+ require('@convivainc/conviva-react-native-appanalytics').default || {
6
+ HIGHER_ORDER_COMP: (Component) => Component,
7
+ }
8
+ )`);
9
+
10
+ const createHigherOrderComponent = template(`
11
+ const COMPONENT_ID = HIGHER_ORDER_COMP_CALL_EXPRESSION;
12
+ `);
13
+
14
+ const ALLOWED_TOUCHABLE_COMPONENTS = [
15
+ 'TouchableOpacity',
16
+ 'TouchableNativeFeedback',
17
+ 'TouchableWithoutFeedback',
18
+ 'TouchableHighlight',
19
+ ];
20
+
21
+ const replaceWithTouchableAutoTrackHigherOrderComponent = path => {
22
+
23
+ if (!ALLOWED_TOUCHABLE_COMPONENTS.includes(path.node.id.name)) {
24
+ return;
25
+ }
26
+ // console.log("replaceWithTouchableAutoTrackHigherOrderComponent++");
27
+
28
+ const equivalentExpression = t.classExpression(
29
+ path.node.id,
30
+ path.node.superClass,
31
+ path.node.body,
32
+ path.node.decorators || []
33
+ );
34
+
35
+ const hocID = t.identifier('convivaTouchableAutoTrack');
36
+
37
+ const convivaImport = convivaLibImport({
38
+ HIGHER_ORDER_COMP: hocID,
39
+ });
40
+
41
+ const autotrackExpression = t.callExpression(
42
+ t.memberExpression(convivaImport.expression, hocID),
43
+ [equivalentExpression]
44
+ );
45
+
46
+ const replacement = createHigherOrderComponent({
47
+ COMPONENT_ID: path.node.id,
48
+ HIGHER_ORDER_COMP_CALL_EXPRESSION: autotrackExpression,
49
+ });
50
+
51
+ path.replaceWith(replacement);
52
+
53
+ // console.log("replaceWithTouchableAutoTrackHigherOrderComponent--");
54
+ };
55
+
56
+ function transform(babel) {
57
+ return {
58
+ visitor: {
59
+ ClassDeclaration(path) {
60
+ replaceWithTouchableAutoTrackHigherOrderComponent(path);
61
+ },
62
+ },
63
+ };
64
+ }
65
+
66
+ module.exports = transform;
@@ -45,7 +45,7 @@
45
45
  #import <ConvivaAppAnalytics/CATEcommerce.h>
46
46
  #import <ConvivaAppAnalytics/CATDeepLinkReceived.h>
47
47
  #import <ConvivaAppAnalytics/CATMessageNotification.h>
48
-
48
+ #import <Foundation/NSObject.h>
49
49
 
50
50
  @implementation RNConvivaTracker
51
51
 
@@ -242,6 +242,17 @@ RCT_EXPORT_METHOD(trackScreenViewEvent:
242
242
  id<CATTrackerController> trackerController = [self trackerByNamespace:namespace];
243
243
 
244
244
  if (trackerController != nil) {
245
+
246
+ BOOL trackScreenView = NO;
247
+ if([(NSObject*)trackerController respondsToSelector:@selector(screenViewAutotracking)]) {
248
+ trackScreenView = [(NSObject*)trackerController performSelector:@selector(screenViewAutotracking)];
249
+ }
250
+
251
+ if(!trackScreenView) {
252
+ resolve(@YES);
253
+ return;
254
+ }
255
+
245
256
  NSDictionary *argmap = [details objectForKey:@"eventData"];
246
257
  NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
247
258
 
@@ -626,10 +637,10 @@ RCT_EXPORT_METHOD(trackCustomEvent:
626
637
 
627
638
  if (trackerController != nil) {
628
639
  NSString *eventName = [details objectForKey:@"eventName"];
629
- NSString *eventData = [details objectForKey:@"eventData"];
640
+ NSDictionary *eventData = [details objectForKey:@"eventData"];
630
641
 
631
642
  if(0 < eventName.length){
632
- [trackerController trackCustomEvent:eventName data:eventData];
643
+ [trackerController trackCustomEvent:eventName eventData:eventData];
633
644
  }
634
645
 
635
646
  resolve(@YES);
@@ -1000,13 +1011,20 @@ RCT_EXPORT_METHOD(getIsInBackground:
1000
1011
  (NSDictionary *)details
1001
1012
  resolver:(RCTPromiseResolveBlock)resolve
1002
1013
  rejecter:(RCTPromiseRejectBlock)reject) {
1003
- NSString *namespace = [details objectForKey:@"tracker"];
1004
- id<CATTrackerController> trackerController = [self trackerByNamespace:namespace];
1005
-
1006
- if (trackerController != nil) {
1007
- BOOL isInBg = [trackerController.session isInBackground];
1008
- resolve(@(isInBg));
1009
- } else {
1014
+ // NSString *namespace = [details objectForKey:@"tracker"];
1015
+ // id<CATTrackerController> trackerController = [self trackerByNamespace:namespace];
1016
+ //
1017
+ // if (trackerController != nil) {
1018
+ // BOOL isInBg = [trackerController.session isInBackground];
1019
+ // resolve(@(isInBg));
1020
+ // } else {
1021
+ // NSError* error = [NSError errorWithDomain:@"ConvivaAppAnalytics" code:200 userInfo:nil];
1022
+ // reject(@"ERROR", @"tracker with given namespace not found", error);
1023
+ // }
1024
+
1025
+ @try {
1026
+ resolve(@(YES));
1027
+ } @catch (NSException *exception) {
1010
1028
  NSError* error = [NSError errorWithDomain:@"ConvivaAppAnalytics" code:200 userInfo:nil];
1011
1029
  reject(@"ERROR", @"tracker with given namespace not found", error);
1012
1030
  }
@@ -1016,13 +1034,19 @@ RCT_EXPORT_METHOD(getBackgroundIndex:
1016
1034
  (NSDictionary *)details
1017
1035
  resolver:(RCTPromiseResolveBlock)resolve
1018
1036
  rejecter:(RCTPromiseRejectBlock)reject) {
1019
- NSString *namespace = [details objectForKey:@"tracker"];
1020
- id<CATTrackerController> trackerController = [self trackerByNamespace:namespace];
1021
-
1022
- if (trackerController != nil) {
1023
- NSInteger bgIdx = [trackerController.session backgroundIndex];
1024
- resolve(@(bgIdx));
1025
- } else {
1037
+ // NSString *namespace = [details objectForKey:@"tracker"];
1038
+ // id<CATTrackerController> trackerController = [self trackerByNamespace:namespace];
1039
+ //
1040
+ // if (trackerController != nil) {
1041
+ // NSInteger bgIdx = [trackerController.session backgroundIndex];
1042
+ // resolve(@(bgIdx));
1043
+ // } else {
1044
+ // NSError* error = [NSError errorWithDomain:@"ConvivaAppAnalytics" code:200 userInfo:nil];
1045
+ // reject(@"ERROR", @"tracker with given namespace not found", error);
1046
+ // }
1047
+ @try {
1048
+ resolve(@(YES));
1049
+ } @catch (NSException *exception) {
1026
1050
  NSError* error = [NSError errorWithDomain:@"ConvivaAppAnalytics" code:200 userInfo:nil];
1027
1051
  reject(@"ERROR", @"tracker with given namespace not found", error);
1028
1052
  }
@@ -1032,20 +1056,83 @@ RCT_EXPORT_METHOD(getForegroundIndex:
1032
1056
  (NSDictionary *)details
1033
1057
  resolver:(RCTPromiseResolveBlock)resolve
1034
1058
  rejecter:(RCTPromiseRejectBlock)reject) {
1059
+ // NSString *namespace = [details objectForKey:@"tracker"];
1060
+ // id<CATTrackerController> trackerController = [self trackerByNamespace:namespace];
1061
+ //
1062
+ // if (trackerController != nil) {
1063
+ // NSInteger fgIdx = [trackerController.session foregroundIndex];
1064
+ // resolve(@(fgIdx));
1065
+ // } else {
1066
+ // NSError* error = [NSError errorWithDomain:@"ConvivaAppAnalytics" code:200 userInfo:nil];
1067
+ // reject(@"ERROR", @"tracker with given namespace not found", error);
1068
+ // }
1069
+ @try {
1070
+ resolve(@(YES));
1071
+ } @catch (NSException *exception) {
1072
+ NSError* error = [NSError errorWithDomain:@"ConvivaAppAnalytics" code:200 userInfo:nil];
1073
+ reject(@"ERROR", @"tracker with given namespace not found", error);
1074
+ }
1075
+ }
1076
+
1077
+ - (nullable id<CATTrackerController>)trackerByNamespace:(NSString *)namespace {
1078
+ return [namespace isEqual:[NSNull null]] ? [CATAppAnalytics defaultTracker] : [CATAppAnalytics trackerByNamespace:namespace];
1079
+ }
1080
+
1081
+ RCT_EXPORT_METHOD(trackClickEvent:
1082
+ (NSDictionary *)details
1083
+ resolver:(RCTPromiseResolveBlock)resolve
1084
+ rejecter:(RCTPromiseRejectBlock)reject) {
1085
+
1035
1086
  NSString *namespace = [details objectForKey:@"tracker"];
1087
+
1036
1088
  id<CATTrackerController> trackerController = [self trackerByNamespace:namespace];
1037
1089
 
1038
1090
  if (trackerController != nil) {
1039
- NSInteger fgIdx = [trackerController.session foregroundIndex];
1040
- resolve(@(fgIdx));
1091
+
1092
+ NSDictionary *eventData = [details objectForKey:@"eventData"];
1093
+
1094
+ if(nil != eventData && 0 < eventData.count){
1095
+
1096
+ NSMutableDictionary *data = [NSMutableDictionary new];
1097
+
1098
+ NSString *elementType = eventData[@"elementType"] ?: @"";
1099
+ if(0 < elementType.length){
1100
+ data[@"elementType"] = elementType;
1101
+ }
1102
+
1103
+ NSString *elementId = eventData[@"elementId"] ?: @"";
1104
+ if(0 < elementId.length){
1105
+ data[@"elementId"] = elementId;
1106
+ }
1107
+
1108
+ NSString *elementName = eventData[@"elementName"] ?: @"";
1109
+ if(0 < elementName.length){
1110
+ data[@"elementName"] = elementName;
1111
+ }
1112
+
1113
+ NSString *elementClasses = eventData[@"elementClasses"] ?: @"";
1114
+ if(0 < elementClasses.length){
1115
+ data[@"elementClasses"] = elementClasses;
1116
+ }
1117
+
1118
+ NSString *elementText = eventData[@"elementText"] ?: @"";
1119
+ if(0 < elementText.length){
1120
+ data[@"elementText"] = elementText;
1121
+ }
1122
+
1123
+ NSString *elementValue = eventData[@"elementValue"] ?: @"";
1124
+ if(0 < elementValue.length){
1125
+ data[@"elementValue"] = elementValue;
1126
+ }
1127
+
1128
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"kCATNotificationButtonClick" object:nil userInfo:data];
1129
+ }
1130
+
1131
+ resolve(@(YES));
1041
1132
  } else {
1042
1133
  NSError* error = [NSError errorWithDomain:@"ConvivaAppAnalytics" code:200 userInfo:nil];
1043
1134
  reject(@"ERROR", @"tracker with given namespace not found", error);
1044
1135
  }
1045
1136
  }
1046
1137
 
1047
- - (nullable id<CATTrackerController>)trackerByNamespace:(NSString *)namespace {
1048
- return [namespace isEqual:[NSNull null]] ? [CATAppAnalytics defaultTracker] : [CATAppAnalytics trackerByNamespace:namespace];
1049
- }
1050
-
1051
1138
  @end
@@ -22,6 +22,6 @@
22
22
 
23
23
  @implementation RNTrackerVersion
24
24
 
25
- NSString * const kRNTrackerVersion = @"rn-0.1.2";
25
+ NSString * const kRNTrackerVersion = @"rn-0.1.5";
26
26
 
27
27
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convivainc/conviva-react-native-appanalytics",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "description": "Conviva React Native Application Analytics Library",
5
5
  "main": "conviva-react-native-appanalytics.js",
6
6
  "repository": {