@convivainc/conviva-react-native-appanalytics 0.1.1 → 0.1.4

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 (37) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/README.md +50 -0
  3. package/RNConvivaAppAnalytics.podspec +1 -1
  4. package/android/.gradle/7.5/checksums/checksums.lock +0 -0
  5. package/android/.gradle/7.5/checksums/md5-checksums.bin +0 -0
  6. package/android/.gradle/7.5/checksums/sha1-checksums.bin +0 -0
  7. package/android/.gradle/7.5/dependencies-accessors/dependencies-accessors.lock +0 -0
  8. package/android/.gradle/7.5/dependencies-accessors/gc.properties +0 -0
  9. package/android/.gradle/7.5/executionHistory/executionHistory.lock +0 -0
  10. package/android/.gradle/7.5/fileChanges/last-build.bin +0 -0
  11. package/android/.gradle/7.5/fileHashes/fileHashes.bin +0 -0
  12. package/android/.gradle/7.5/fileHashes/fileHashes.lock +0 -0
  13. package/android/.gradle/7.5/fileHashes/resourceHashesCache.bin +0 -0
  14. package/android/.gradle/7.5/gc.properties +0 -0
  15. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  16. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  17. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  18. package/android/.gradle/config.properties +2 -0
  19. package/android/.gradle/vcs-1/gc.properties +0 -0
  20. package/android/.idea/compiler.xml +6 -0
  21. package/android/.idea/gradle.xml +19 -0
  22. package/android/.idea/migrations.xml +10 -0
  23. package/android/.idea/misc.xml +10 -0
  24. package/android/.idea/vcs.xml +6 -0
  25. package/android/build.gradle +4 -4
  26. package/android/local.properties +8 -0
  27. package/android/src/main/java/com/conviva/react/apptracker/RNConvivaTrackerModule.java +74 -41
  28. package/android/src/main/java/com/conviva/react/apptracker/util/EventUtil.java +7 -0
  29. package/android/src/main/java/com/conviva/react/apptracker/util/TrackerVersion.java +1 -1
  30. package/conviva-react-native-appanalytics.d.ts +17 -1
  31. package/conviva-react-native-appanalytics.js +346 -2
  32. package/instrumentation/index.js +66 -0
  33. package/ios/RNConvivaAppAnalytics.m +113 -16
  34. package/ios/Util/RNConfigUtils.h +2 -0
  35. package/ios/Util/RNConfigUtils.m +8 -0
  36. package/ios/Util/RNTrackerVersion.m +1 -1
  37. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
 
2
2
  # Changelog
3
+
4
+ ## 0.1.4 (05/JAN/2024)
5
+ - 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>
6
+ *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*
7
+
8
+ ## 0.1.3 (12/DEC/2023)
9
+ * Supports the Auto Detection of "buttonText" style for the User Click of Button, TouchableHighlight, TouchableOpacity, TouchableWithoutFeedback and TouchableNativeFeedback Components<br>
10
+ *This feature needs the Android App SDK version of [0.8.0](https://github.com/Conviva/conviva-android-appanalytics)*
11
+
12
+ ## 0.1.2 (01/MAY/2023)
13
+ * Supports the inclusion of the latest Android/iOS Native sensor always in the Android/iOS Bridge going forward
14
+ * Fixes the issue of App Name being incorrect for iOS Bridge
15
+ * Updates related to the default Network and Tracker Config in the iOS Bridge
16
+
3
17
  ## 0.1.1 (24/APR/2023)
4
18
  * Published the Android/iOS folders along with the podspec files
5
19
 
@@ -8,4 +22,4 @@
8
22
  * Fixes the issue of optional Network Config argument being mandatory
9
23
 
10
24
  ## 0.0.1 (02/APR/2023)
11
- * Initial version of the Conviva React Native Sensor
25
+ * Initial version of the Conviva React Native Sensor
package/README.md CHANGED
@@ -10,6 +10,15 @@ npm install @convivainc/conviva-react-native-appanalytics --save
10
10
  npx pod-install
11
11
  ```
12
12
 
13
+ ## Android Gradle dependency
14
+ Add the following line to app's build.gradle file along with the dependencies:
15
+ ```
16
+ dependencies {
17
+ ...
18
+ implementation 'com.conviva.sdk:conviva-android-tracker:<version>'
19
+ }
20
+ ```
21
+
13
22
  ## Initialize the tracker
14
23
  ```js
15
24
  import { createTracker } from '@convivainc/conviva-react-native-appanalytics';
@@ -44,6 +53,47 @@ let pageViewEvent = {'pageUrl' : 'https://allpopulated.com',
44
53
  tracker.trackPageViewEvent(pageViewEvent);
45
54
  ```
46
55
 
56
+ ## Auto detect ScreenView Events for tracking screen navigation.
57
+ For React Navigation versions 5 and above, to autocapture screenviews, wrap withReactNavigationAutotrack(autocaptureNavigationTrack) around the NavigationContainer:
58
+
59
+ ```js
60
+
61
+ import {
62
+ withReactNavigationAutotrack,
63
+ autocaptureNavigationTrack
64
+ } from '@convivainc/conviva-react-native-appanalytics';
65
+
66
+
67
+ const ConvivaNavigationContainer =
68
+ withReactNavigationAutotrack(autocaptureNavigationTrack)(NavigationContainer);
69
+
70
+
71
+ <ConvivaNavigationContainer>
72
+ <Tab.Navigator>
73
+ <Tab.Screen name="Home" component={HomeScreen} />
74
+ <Tab.Screen name="Settings" component={SettingsScreen}/>
75
+ </Tab.Navigator>
76
+ </ConvivaNavigationContainer>
77
+ ```
78
+
79
+ For React Navigation versions below 5, wrap the AppContainer (the result of a call to React Navigation’s createAppContainer() method) with withReactNavigationAutotrack(autocaptureNavigationTrack)
80
+ ```js
81
+
82
+ let AppNavigator = createStackNavigator(
83
+ {
84
+ Home: { screen: HomeScreen },
85
+ Settings: { screen: SettingsScreen }
86
+ },
87
+ {
88
+ initialRouteName: 'HomeScreen'
89
+ }
90
+ )
91
+
92
+ let App = withReactNavigationAutotrack(autocaptureNavigationTrack)(AppNavigator);
93
+
94
+ ```
95
+
96
+
47
97
  ## Custom event tracking to track your application specific events and state changes
48
98
  Use trackCustomEvent() API to track all kinds of events. This API provides 2 fields to describe the tracked events.
49
99
 
@@ -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.10"
23
+ s.dependency "ConvivaAppAnalytics", ">= 0.2.18"
24
24
  end
File without changes
@@ -0,0 +1,2 @@
1
+ #Mon Dec 18 17:16:15 IST 2023
2
+ gradle.version=7.5
@@ -0,0 +1,2 @@
1
+ #Mon Dec 18 17:16:12 IST 2023
2
+ java.home=/private/var/folders/k4/74893875541dtbxdz44z6zbr0000gn/T/AppTranslocation/4A54960E-0028-414A-AF27-0F092C67D374/d/Android Studio.app/Contents/jbr/Contents/Home
File without changes
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="CompilerConfiguration">
4
+ <bytecodeTargetLevel target="11" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="GradleMigrationSettings" migrationVersion="1" />
4
+ <component name="GradleSettings">
5
+ <option name="linkedExternalProjectsSettings">
6
+ <GradleProjectSettings>
7
+ <option name="testRunner" value="GRADLE" />
8
+ <option name="externalProjectPath" value="$PROJECT_DIR$" />
9
+ <option name="gradleJvm" value="Embedded JDK" />
10
+ <option name="modules">
11
+ <set>
12
+ <option value="$PROJECT_DIR$" />
13
+ </set>
14
+ </option>
15
+ <option name="resolveExternalAnnotations" value="false" />
16
+ </GradleProjectSettings>
17
+ </option>
18
+ </component>
19
+ </project>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectMigrations">
4
+ <option name="MigrateToGradleLocalJavaHome">
5
+ <set>
6
+ <option value="$PROJECT_DIR$" />
7
+ </set>
8
+ </option>
9
+ </component>
10
+ </project>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ExternalStorageConfigurationManager" enabled="true" />
4
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
5
+ <output url="file://$PROJECT_DIR$/build/classes" />
6
+ </component>
7
+ <component name="ProjectType">
8
+ <option name="id" value="Android" />
9
+ </component>
10
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5
+ </component>
6
+ </project>
@@ -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
  }
@@ -51,5 +51,5 @@ dependencies {
51
51
  implementation "com.squareup.okhttp3:okhttp:4.9.3"
52
52
  implementation "com.facebook.react:react-native:+"
53
53
  implementation 'com.googlecode.json-simple:json-simple:1.1'
54
- implementation 'com.conviva.sdk:conviva-android-tracker:0.5.+'
54
+ implementation 'com.conviva.sdk:conviva-android-tracker:+'
55
55
  }
@@ -0,0 +1,8 @@
1
+ ## This file must *NOT* be checked into Version Control Systems,
2
+ # as it contains information specific to your local configuration.
3
+ #
4
+ # Location of the SDK. This is only used by Gradle.
5
+ # For customization when using a Version Control System, please read the
6
+ # header note.
7
+ #Mon Dec 18 17:16:12 IST 2023
8
+ sdk.dir=/Users/sramachandra/Library/Android/sdk
@@ -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.1";
7
+ public final static String RN_CONVIVA_TRACKER_VERSION = "rn-0.1.4";
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
 
@@ -61,17 +61,32 @@ RCT_EXPORT_METHOD(createTracker:
61
61
  NSString *customerKey = [argmap objectForKey:@"customerKey"];
62
62
  NSDictionary *networkConfig =[argmap objectForKey:@"networkConfig"];
63
63
 
64
- // NetworkConfiguration
65
- NSString *method = [networkConfig rncat_stringForKey:@"method" defaultValue:nil];
66
- CATHttpMethod httpMethod = [@"get" isEqualToString:method] ? CATHttpMethodGet : CATHttpMethodPost;
67
- CATNetworkConfiguration *networkConfiguration = [[CATNetworkConfiguration alloc] initWithEndpoint:networkConfig[@"endpoint"] method:httpMethod];
68
- NSString *customPostPath = [networkConfig rncat_stringForKey:@"customPostPath" defaultValue:nil];
69
- if (customPostPath != nil) {
70
- networkConfiguration.customPostPath = customPostPath;
71
- }
72
- NSObject *requestHeaders = [networkConfig objectForKey:@"requestHeaders"];
73
- if (requestHeaders != nil && [requestHeaders isKindOfClass:NSDictionary.class]) {
74
- networkConfiguration.requestHeaders = (NSDictionary *)requestHeaders;
64
+ CATNetworkConfiguration *networkConfiguration = nil;
65
+ if(nil != networkConfig){
66
+
67
+ // NetworkConfiguration
68
+ NSString *method = [networkConfig rncat_stringForKey:@"method" defaultValue:nil];
69
+ CATHttpMethod httpMethod = CATHttpMethodPost;
70
+
71
+ if(0 < [method length]){
72
+ httpMethod = [@"get" isEqualToString:method] ? CATHttpMethodGet : CATHttpMethodPost;
73
+ }
74
+
75
+ NSString *endpoint = networkConfig[@"endpoint"];
76
+
77
+ if(0 < [endpoint length]) {
78
+ networkConfiguration = [[CATNetworkConfiguration alloc] initWithEndpoint:networkConfig[@"endpoint"] method:httpMethod];
79
+ }
80
+
81
+ NSString *customPostPath = [networkConfig rncat_stringForKey:@"customPostPath" defaultValue:nil];
82
+ if (0 < [customPostPath length]) {
83
+ networkConfiguration.customPostPath = customPostPath;
84
+ }
85
+
86
+ NSObject *requestHeaders = [networkConfig objectForKey:@"requestHeaders"];
87
+ if (requestHeaders != nil && [requestHeaders isKindOfClass:NSDictionary.class]) {
88
+ networkConfiguration.requestHeaders = (NSDictionary *)requestHeaders;
89
+ }
75
90
  }
76
91
 
77
92
  // Configurations
@@ -83,6 +98,10 @@ RCT_EXPORT_METHOD(createTracker:
83
98
  CATTrackerConfiguration *trackerConfiguration = [RNConfigUtils mkTrackerConfig:(NSDictionary *)trackerArg];
84
99
  [controllers addObject:trackerConfiguration];
85
100
  }
101
+ else{
102
+ CATTrackerConfiguration *trackerConfiguration = [RNConfigUtils mkDefaultTrackerConfig];
103
+ [controllers addObject:trackerConfiguration];
104
+ }
86
105
 
87
106
  // SessionConfiguration
88
107
  NSObject *sessionArg = [argmap objectForKey:@"sessionConfig"];
@@ -118,10 +137,20 @@ RCT_EXPORT_METHOD(createTracker:
118
137
  CATGlobalContextsConfiguration *gcConfiguration = [RNConfigUtils mkGCConfig:(NSArray *)gcArg];
119
138
  [controllers addObject:gcConfiguration];
120
139
  }
121
-
122
- id<CATTrackerController> tracker = [CATAppAnalytics createTrackerWithNamespace:trackerNs customerKey:customerKey network:networkConfiguration configurations:controllers];
123
- tracker.appId = appName;
124
-
140
+
141
+ id<CATTrackerController> tracker = nil;
142
+ if(nil != networkConfiguration){
143
+ tracker = [CATAppAnalytics createTrackerWithCustomerKey:customerKey
144
+ appName:appName
145
+ network:networkConfiguration
146
+ configurations:controllers];
147
+ }
148
+ else{
149
+ tracker = [CATAppAnalytics createTrackerWithCustomerKey:customerKey
150
+ appName:appName
151
+ configurations:controllers];
152
+ }
153
+
125
154
  if (tracker) {
126
155
  resolve(@YES);
127
156
  } else {
@@ -213,6 +242,17 @@ RCT_EXPORT_METHOD(trackScreenViewEvent:
213
242
  id<CATTrackerController> trackerController = [self trackerByNamespace:namespace];
214
243
 
215
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
+
216
256
  NSDictionary *argmap = [details objectForKey:@"eventData"];
217
257
  NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
218
258
 
@@ -1019,4 +1059,61 @@ RCT_EXPORT_METHOD(getForegroundIndex:
1019
1059
  return [namespace isEqual:[NSNull null]] ? [CATAppAnalytics defaultTracker] : [CATAppAnalytics trackerByNamespace:namespace];
1020
1060
  }
1021
1061
 
1062
+ RCT_EXPORT_METHOD(trackClickEvent:
1063
+ (NSDictionary *)details
1064
+ resolver:(RCTPromiseResolveBlock)resolve
1065
+ rejecter:(RCTPromiseRejectBlock)reject) {
1066
+
1067
+ NSString *namespace = [details objectForKey:@"tracker"];
1068
+
1069
+ id<CATTrackerController> trackerController = [self trackerByNamespace:namespace];
1070
+
1071
+ if (trackerController != nil) {
1072
+
1073
+ NSDictionary *eventData = [details objectForKey:@"eventData"];
1074
+
1075
+ if(nil != eventData && 0 < eventData.count){
1076
+
1077
+ NSMutableDictionary *data = [NSMutableDictionary new];
1078
+
1079
+ NSString *elementType = eventData[@"elementType"] ?: @"";
1080
+ if(0 < elementType.length){
1081
+ data[@"elementType"] = elementType;
1082
+ }
1083
+
1084
+ NSString *elementId = eventData[@"elementId"] ?: @"";
1085
+ if(0 < elementId.length){
1086
+ data[@"elementId"] = elementId;
1087
+ }
1088
+
1089
+ NSString *elementName = eventData[@"elementName"] ?: @"";
1090
+ if(0 < elementName.length){
1091
+ data[@"elementName"] = elementName;
1092
+ }
1093
+
1094
+ NSString *elementClasses = eventData[@"elementClasses"] ?: @"";
1095
+ if(0 < elementClasses.length){
1096
+ data[@"elementClasses"] = elementClasses;
1097
+ }
1098
+
1099
+ NSString *elementText = eventData[@"elementText"] ?: @"";
1100
+ if(0 < elementText.length){
1101
+ data[@"elementText"] = elementText;
1102
+ }
1103
+
1104
+ NSString *elementValue = eventData[@"elementValue"] ?: @"";
1105
+ if(0 < elementValue.length){
1106
+ data[@"elementValue"] = elementValue;
1107
+ }
1108
+
1109
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"kCATNotificationButtonClick" object:nil userInfo:data];
1110
+ }
1111
+
1112
+ resolve(@(YES));
1113
+ } else {
1114
+ NSError* error = [NSError errorWithDomain:@"ConvivaAppAnalytics" code:200 userInfo:nil];
1115
+ reject(@"ERROR", @"tracker with given namespace not found", error);
1116
+ }
1117
+ }
1118
+
1022
1119
  @end
@@ -29,6 +29,8 @@
29
29
 
30
30
  @interface RNConfigUtils : NSObject
31
31
 
32
+ + (CATTrackerConfiguration *) mkDefaultTrackerConfig;
33
+
32
34
  + (CATTrackerConfiguration *) mkTrackerConfig:(NSDictionary *) trackerConfig;
33
35
 
34
36
  + (CATSessionConfiguration *) mkSessionConfig:(NSDictionary *) sessionConfig;
@@ -37,6 +37,14 @@
37
37
 
38
38
  @implementation RNConfigUtils
39
39
 
40
+ + (CATTrackerConfiguration *) mkDefaultTrackerConfig {
41
+
42
+ CATTrackerConfiguration *trackerConfiguration = [CATTrackerConfiguration new];
43
+ trackerConfiguration.trackerVersionSuffix = kRNTrackerVersion;
44
+
45
+ return trackerConfiguration;
46
+ }
47
+
40
48
  + (CATTrackerConfiguration *) mkTrackerConfig:(NSDictionary *) trackerConfig {
41
49
  CATTrackerConfiguration *trackerConfiguration = [CATTrackerConfiguration new];
42
50
  trackerConfiguration.trackerVersionSuffix = kRNTrackerVersion;
@@ -22,6 +22,6 @@
22
22
 
23
23
  @implementation RNTrackerVersion
24
24
 
25
- NSString * const kRNTrackerVersion = @"rn-0.1.1";
25
+ NSString * const kRNTrackerVersion = @"rn-0.1.4";
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.1",
3
+ "version": "0.1.4",
4
4
  "description": "Conviva React Native Application Analytics Library",
5
5
  "main": "conviva-react-native-appanalytics.js",
6
6
  "repository": {