1.0.5 • Published 5 years ago
apxor-react-native-sdk v1.0.5
apxor-react-native-sdk
Getting started
$ npm install apxor-react-native-sdk --save
Mostly automatic installation
$ react-native link apxor-react-native-sdk
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.apxor.reactnativesdk.ApxorReactNativeSdkPackage;
to the imports at the top of the file - Add
new ApxorReactNativeSdkPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':apxor-react-native-sdk' project(':apxor-react-native-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/apxor-react-native-sdk/android')
Additional steps todo
Insert the following lines inside repositories block in
android/build.gradle
maven { url "http://repo.apxor.com/artifactory/list/libs-release-android/" }
Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':apxor-react-native-sdk') implementation 'com.apxor.android:apxor-android-sdk-core:2.3.7@aar'
Insert the following lines in the onCreate method in
android/app/src/main/java/(package)/MainApplication.java
:ApxorSDK.initialize("<APP_ID>", MainApplication.this);
Note:
- The second argument,
MainApplication.this
, makes sures to provide ApplicationContext instead of ReactApplicationContext for ApxorSDK to work properly. - If you change the application class name (default:
MainApplication
), make sure to useyour_class_name.this
instead.
- The second argument,
Push Notification Module (Optional)
Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation 'com.apxor.android:apxor-android-sdk-push:1.1.5@aar' implementation 'com.google.firebase:firebase-messaging:11.4.0'
Insert the following piece of code in the onMessageReceived(RemoteMessage) function
if (ApxorPushAPI.isApxorNotification(message)) { ApxorPushAPI.handleNotification(message, getApplicationContext()); }
Usage
import ApxorReactNativeSdk from 'apxor-react-native-sdk';
UserId:
ApxorReactNativeSdk.setUserIdentifier("user_id");
Example
ApxorReactNativeSdk.setUserIdentifier("<some_user_id>");
Events:
ApxorReactNativeSdk.logAppEvent(event_name, properties);
Example
ApxorReactNativeSdk.logAppEvent("ADD_TO_CART", {
"userId": "user@example.com",
"value": "1299",
"item": "Sony Head Phone 1201"
});
User Properties:
ApxorReactNativeSdk.setUserCustomInfo(properties);
Example
ApxorReactNativeSdk.setUserCustomInfo({
"property1": "value",
"property2": "value2"
});
Track Navigation:
ApxorReactNativeSdk.logNavigationEvent(screen_name);
Example
ApxorReactNativeSdk.logNavigationEvent("LoginScreen");