SDK Integration - React native integration 

Page / - last modified by Developer on 2020/01/03 12:47 

React native integration 
last modified by Developer
on 2020/01/03 12:47

Table of Contents
1. Overview
2. Adding SDK to the project
3. Api methods
3.1 SDK initialization
3.2 Tracking in app events
3.2.1 Overview
3.2.2 Implementation
3.2.3 Event categories
3.2.4 Event parameters
3.3 Remaining methods
4. Constants
4.1 User field constants
4.2 Data gather policy constants
4.3 Data collectors constants
4.4 Category and parameter constants
5. Sample app

Page Contents
•	1. Overview
•	2. Adding SDK to the project
•	3. Api methods
•	3.1 SDK initialization
•	3.2 Tracking in app events
•	3.2.1 Overview
•	3.2.2 Implementation
•	3.2.3 Event categories
•	3.2.4 Event parameters
•	3.3 Remaining methods
•	4. Constants
•	4.1 User field constants
•	4.2 Data gather policy constants
•	4.3 Data collectors constants
•	4.4 Category and parameter constants
•	5. Sample app
1. Overview
The plugin is located at npmjs repositories (npm repositories)
This plugin is built for:
•	Mobigate SDK version 1.0.4
2. Adding SDK to the project
First, install library from the repository with
yarn add react-native-mobigate
or
npm install react-native-mobigate --save
Link newly added plugin
•	React Native >= 0.60
Starting from React Native 0.60, autolinking makes the installation process simpler
•	React Native <= 0.59
•	Mostly automatic installation:
react-native link react-native-mobigate
•	Manual installation:
Manually link the library on Android

•	Add to: android/settings.gradle
include ':react-native-mobigate'
project(':react-native-mobigate').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mobigate/android')
•	Add to: android/app/build.gradle
dependencies {
implementation project(':react-native-mobigate')
}
•	Add the MobigatePackage class to your list of exported packages into: android/app/src/main/.../MainApplication.java
...
import pl.spicymobile.reactmobigate.MobigatePackage;

@Override
protected List<ReactPackage> getPackages() {
   return Arrays.<ReactPackage>asList(
       new MainReactPackage(), 
       new MobigatePackage()
    );
}

3. Api methods
To use any method from the plugin add import:
import Mobigate from 'react-native-mobigate'
3.1 SDK initialization
You must initialize the library before running it. Use init(apiKey, options, onSuccess, onError) method for that:
Mobigate.init(apiKey, options, onSuccess, onError)
Parameter	Type	Description	
apiKey	String	Api key provided by your business partner	
options	Json Object	SDK configuration 	
onSuccess	Function	returns callback object	
onError	Function	returns callback object	
Options

Name	Type	Default	Description	
 appIdentifier	String	 	 Application identifier	
appInstallationSource 	String	 	 App installation source e.g., google-play, organic.	
email 	String 	 	 Set's user email.	
customUserId 	String 	 	 You may use your custom userID for marking data. By default we are using device ID and emails for matching. Set it before starting the service using MobigateSDk.Builder method.	
 enableUserFields	Json Array 	 	 Enable custom fields in user data. By default MobienceSDK is gathering all identifiers, which it can read. You can choose one of these field: ["email", "imei", "imsi", "msisdn", "mac", "serial"] see plugin user field constants.	
 dataGatherPolicy	 Json Object	 	 Enable custom data gater policy. By default MobienceSDK gather all data it can read and hide notification icon. Check below DataGatherPolicy options for more details.	
 enableIdProfiles	Boolean 	false 	 turns on / off the IDs profiles system.	

DataGatherPolicy options

Name	Type	Default	Description	
 monitorState	String	 	 Possible monitor states: plugin constants. More info about gathering data here	
notificationText	String	 	 if state = Mobigate.DATA_GATHER_POLICY_DEFAULT you can pass custom foreground service notification text	

When the library is already initialized run it. Use startSDK(onSuccess, onError) method for that:
Mobigate.startSDK(onSuccess, onError) 
Parameter	Type	Description	
onSuccess	Function	returns callback object	
onError	Function	returns callback object	
Example

  initLibrary = () => {
   if (Platform.OS === 'android') {
      Mobigate.init("V0K6jhiIfem6CRWHYZ59Nmj3oFBBKbJsnSsWfR2JNq7ktblOUXwbJoBQTpWnw2uSwW76gpiu2kun50jweTY69B",
        {
         /*custom options, check docs for more details
           appIdentifier: 'customUserAppIdentifier',
           appInstallationSource: "customAppInstallationSourcexyz",
           email: 'testemail@gmail.com',
           userAgent: 'customUserAgent',
           customUserId: 'customUserId',*/
        }, (success) => {
         /* You can configure custom collectors after init 
          Mobigate.disableAllDataCollector()
          Mobigate.configureDataCollectors(true, [Mobigate.DATA_COLLECTOR_APPS_LIST,
          Mobigate.DATA_COLLECTOR_BATTERY,
          Mobigate.DATA_COLLECTOR_PHONE_INFO])*/

          Mobigate.startSDK((result) => {
           this.setState({
              status: 'started',
            });

          }, (errorResult) => {
           this.setState({
              status: errorResult,
            });
          })
        }, (initError) => {
         this.setState({
            status: initError,
          });
        })
    }else{
     this.setState({
        status: 'Mobigate SDK supports only Android'
      })
    }
  }

3.2 Tracking in app events
In-App Events provide insight on what is happening in your app. It is recommended to take the time and define the events you would like to measure.
3.2.1 Overview
An event consists of two fields that you  can use to describe a user's interaction with your app content:
Field name	Type	Required	Description	
Category	String	yes	Event category	
Parameter	String	no	Event parameter. 
There can be more than one	
You can use any event category or parameter string of your choice. However, react-native-mobigate plugin contains recommended event categories and parameters via String constants (see Event categories and Event parameters).
3.2.2 Implementation
Tracking in-app events is performed by two methods:
Mobigate.trackEvent(options) 
Options

Name	Type	Default	Description	
name	String 	 	 Event category name.	
parameters	Json array	 	 Array of parameters. Look below on example.	

Example

  sendTrackEvent = () => {
   if (Platform.OS === 'android') {
      Mobigate.trackEvent({
        name: Mobigate.CATEGORY_PURCHASE,
        parameters: {
          [Mobigate.PARAMETER_CONTENT_ID]: 42313532,
          [Mobigate.PARAMETER_PRICE]: 43.23,
          [Mobigate.PARAMETER_QUANTITY]: 2,
         'userCustomParameterName':'simpleName'
        },
      })
    }
  }

Mobigate.trackAppInstall(timestamp)
Parameter	Type	Description	
timestamp	double	Unix timestamp in milliseconds	
Example

  sendTrackEvent = () => {
   if (Platform.OS === 'android') {
      Mobigate.trackAppInstall(1578042916000)
    }
  }

3.2.3 Event categories
The following section describes the recommended structure of each event category. In-app events categories are defined as part of plugin String constants.
LEVEL_ACCOMPLISHED

Description: Track accomplished game level achievement
Event category: LEVEL_ACCOMPLISHED
Recommended parameters: LEVEL, SCORE

ADD_PAYMENT_INFO

Description: Track payment info
Event category: ADD_PAYMENT_INFO
Recommended parameters: SUCCESS

ADD_TO_BASKET

Description: Track add item to basket
Event category: ADD_TO_BASKET
Recommended parameters: PRICE, CONTENT_TYPE, CONTENT_ID, CONTENT, CURRENCY, QUANTITY

REMOVED_FROM_BASKET

Description: Track removed item from basket
Event category: REMOVED_FROM_BASKET
Recommended parameters: PRICE, CONTENT_TYPE, CONTENT_ID, CONTENT, CURRENCY, QUANTITY

ADD_TO_WISH_LIST

Description: Track add item to wish list
Event category: ADD_TO_WISH_LIST
Recommended parameters: PRICE, CONTENT_TYPE, CONTENT_ID, CONTENT, CURRENCY, QUANTITY

REGISTRATION

Description: Track registration
Event category: REGISTRATION
Recommended parameters: REGISTRATION_METHOD

TUTORIAL_COMPLETION

Description: Track tutorial completion
Event category: TUTORIAL_COMPLETION
Recommended parameters: SUCCESS, CONTENT, CONTENT_ID

TRIGGER_CHECKOUT

Description: Track triggered checkout
Event category: TRIGGER_CHECKOUT
Recommended parameters: PROCE, CONTENT_TYPE, CONTENT_ID, CONTENT, QUANTITY, PAYMENT_INFO_AVAILABLE, CURRENCY

PURCHASE

Description: Track purchased item
Event category: PURCHASE
Recommended parameters: REVENUE, CONTENT_TYPE, CONTENT_ID, CONTENT, PRICE, QUANTITY, CURRENCY, ORDER_ID

SUBSCRIBE

Description: Track subscription purchase
Event category: SUBSCRIBE
Recommended parameters: REVENUE, CURRENCY

BEGIN_TRIAL

Description: Track begin trail of product
Event category: BEGIN_TRIAL
Recommended parameters: PRICE, CURRENCY

RATE

Description: Track app/item rate
Event category: RATE
Recommended parameters: RATING_VALUE, CONTENT_TYPE, CONTENT_ID, CONTENT, MAX_RATING_VALUE

SEARCH

Description: Track search event
Event category: SEARCH
Recommended parameters: CONTENT_TYPE, SEARCH_STRING, SUCCESS

USED_CREDIT

Description: Track use of credit
Event category: USED_CREDIT
Recommended parameters: PRICE, CONTENT_TYPE, CONTENT_ID, CONTENT

UNLOCKED_ACHIEVEMENT

Description: Track achievement unlock
Event category: UNLOCKED_ACHIEVEMENT
Recommended parameters: DESCRIPTION

VIEW_CONTENT

Description: Track content view event
Event category: VIEW_CONTENT
Recommended parameters: PRICE, CONTENT_TYPE, CONTENT_ID, CONTENT, CURRENCY

VIEW_LIST

Description: Track list event
Event category: VIEW_LIST
Recommended parameters: CONTENT_TYPE, CONTENT_LIST

CLICK_AD

Description: Track ad click
Event category: CLICK_AD
Recommended parameters: CONTENT_TYPE, CONTENT_ID

VIEW_AD

Description: Track view ad
Event category: VIEW_AD
Recommended parameters: CONTENT_TYPE, CONTENT_ID

EVENT_BOOKING

Description: Track booking event
Event category: EVENT_BOOKING
Recommended parameters: REVENUE, DESTINATION_A, DESTINATION_B, CLASS, DESCRIPTION, CUSTOMER_USER_ID, CONTENT_TYPE, CONTENT_ID, DATE_A, DATE_B

SHARE

Description: Track share event
Event category: SHARE
Recommended parameters: DESCRIPTION

INVITE

Description: Track social invite event
Event category: INVITE
Recommended parameters: NONE

LOGIN

Description: Track user login event
Event category: LOGIN
Recommended parameters: NONE

EVENT_RETURN

Description: Track re engagement event
Event category: EVENT_RETURN
Recommended parameters: NONE

OPENED_PUSH_NOTIFICATION

Description: Track user opened push notification
Event category: OPENED_PUSH_NOTIFICATION
Recommended parameters: NONE

UPDATE

Description: Track update event
Event category: UPDATE
Recommended parameters: CONTENT_ID

3.2.4 Event parameters
In addition each category that is passed with event may have optional parameters defined as part of the plugin constants, or custom defined as String. Below is a list of recommended parameters.
Parameters list

Parameter enum	Recommended value	
REVENUE	FLoat	
PRICE	Float	
LEVEL	Integer	
SUCCESS	Boolean	
CONTENT_TYPE	String	
CONTENT_LIST	Array of strings	
CONTENT_ID	String	
CURRENCY	String	
REGISTRATION_METHOD	String	
QUANTITY	Integer	
PAYMENT_INFO_AVAILABLE	Boolean	
RATING_VALUE	Float	
MAX_RATING_VALUE	Float	
SEARCH_STRING	String	
DESCRIPTION	String	
SCORE	Integer	
DESTINATION_A	String	
DESTINATION_B	String	
CLASS	String	
DATE_A	String	
DATE_B	String	
EVENT_START	Unixtime	
EVENT_END	Unixtime	
LATITUDE	Double	
LONGITUDE	Double	
CUSTOMER_USER_ID	String	
CUSTOMER_SEGMENT	String	
VALIDATED	String	
RECEIPT_ID	String	
ORDER_ID	String	
TUTORIAL_ID	String	
ACHIEVEMENT_ID	String	
VIRTUAL_CURRENCY_NAME	String	
DEEP_LINK	String	
OLD_VERSION	String	
NEW_VERSION	String	
REVIEW_TEXT	String	
COUPON_CODE	String	
DEPARTING_DEPARTURE_DATE	String	
RETURNING_DEPARTURE_DATE	String	
DESTINATION_LIST	String[]	
CITY	String	
REGION	String	
COUNTRY	String	
DEPARTING_ARRIVAL_DATE	String	
RETURNING_ARRIVAL_DATE	String	
SUGGESTED_DESTINATIONS	String[]	
TRAVEL_START	String	
TRAVEL_END	String	
NUM_ADULTS	Integer	
NUM_CHILDREN	Integer	
NUM_INFANTS	Integer	
SUGGESTED_HOTELS	String[]	
USER_SCORE	Float	
HOTEL_SCORE	Float	
PURCHASE_CURRENCY	String	
PREFERRED_STAR_RATINGS	Integer[2]	
PREFERRED_PRICE_RANGE	Integer[2]	
PREFERRED_NEIGHBORHOODS	String[]	
PREFERRED_NUM_STOPS	Integer	
CONTENT	String	
PARAM_1	String	
PARAM_2	String	
PARAM_3	String	
PARAM_4	String	
PARAM_5	String	
PARAM_6	String	
PARAM_7	String	
PARAM_8	String	
PARAM_9	String	
PARAM_10	String	

3.3 Remaining methods
Mobigate.setCollectAll()
This method enables all data collectors. By default all data collectors are enabled.
Example

Mobigate.disableAllDataCollector()

Mobigate.configureDataCollectors(enable, collectors)
Enable or disable DataCollector by array collectors input
Name	Type	Description		
enable	boolean	true if enable, false if disable	 	
collectors	array of data collector const	e.g.,[Mobigate.DATA_COLLECTOR_BATTERY, DATA_COLLECTOR_GEOLOCATION]	 	
Example

Mobigate.configureDataCollectors(true, [Mobigate.DATA_COLLECTOR_APPS_LIST,
        Mobigate.DATA_COLLECTOR_BATTERY,
        Mobigate.DATA_COLLECTOR_PHONE_INFO])

Mobigate.disableAllDataCollector()
Disable all data collectors
Example

Mobigate.disableAllDataCollector()

Mobigate.setEmail(email)
Set user's email
Name	Type	Description		
email 	String 	user's email address 	 	
Example

Mobigate.setEmail('emailExample@spicymobile.pl')

Mobigate.getEmail(onSuccess, onError)
Get previously set user email
Name	Type	Description	
onSuccess 	Function 	returns callback object 	
onError 	Function 	returns callback object	
Example

Mobigate.getEmail((success) => {
          console.log("user email: " + success)
        }, (error) => {
          console.log(error)
        })

Mobigate.setFbToken(token)
Set fb token for social network collector
Name	Type	Description	
token 	string 	facebook token	
Example

Mobigate.setFbToken('9dsf87ds98978das98d7893u12rj808d0j09012jd012')

Example

Mobigate.setFbToken('9dsf87ds98978das98d7893u12rj808d0j09012jd012')

Mobigate.getSDKInfo(onSuccess, onError)
Getting information about the library
Name	Type	Description	
onSuccess 	Function 	returns callback object 	
onError 	Function 	returns callback object	
Example

Mobigate.getSDKInfo((success) => {
          console.log("sdk info: " + success)
        }, (error) => {
          console.log(error)
        })

Mobigate.getSDKUniqueIdentifier(onSuccess, onError)
Return unique SDK identificator
Name	Type	Description	
onSuccess 	Function 	returns callback object 	
onError 	Function 	returns callback object	
Example

Mobigate.getSDKUniqueIdentifier((success) => {
          console.log("UUID: " + success)
        }, (error) => {
          console.log(error)
        })

Mobigate.getIDsProfiles(onSuccess, onError)
Method returns IDs profiles. List of IDs profiles in the application memory is updated (synchronized with the server) at specified intervals. To enable functionality, use the 'enableIDsProfiles (boolean enable)' method. Returns the identifiers of IDs profiles (ex. 5,9,20), returns '0' if list of user IDs profiles is empty, returns 'null' if the system has not yet communicated
Name	Type	Description	
onSuccess 	Function 	returns callback object 	
onError 	Function 	returns callback object	
Example

Mobigate.getIDsProfiles((success) => {
          console.log("Profiles: " + success)
        }, (error) => {
          console.log(error)
        })

Mobigate.getAdOceanTargeting(onSuccess, onError)
Getting numerical variables, that can be used for ads targeting. Method must be called from separate thread. Return 3 different identifiers of a user, encoded into a map of AdOcean numerical variables
Name	Type	Description	
onSuccess 	Function 	returns callback object 	
onError 	Function 	returns callback object	
Example

Mobigate.getAdOceanTargeting((success) => {
          console.log("Adocean targeting: " + success)
        }, (error) => {
          console.log(error)
        })

4. Constants
The plugin provides many helpful constants for easier implementation.
4.1 User field constants
Used to set custom user fields inside Mobigate.init() method:
•	Mobigate.USER_FIELD_EMAIL
•	Mobigate.USER_FIELD_IMSI
•	Mobigate.USER_FIELD_IMEI
•	Mobigate.USER_FIELD_SERIAL
4.2 Data gather policy constants
Used to set how the library collects data:
•	Mobigate.DATA_GATHER_POLICY_DEFAULT
•	Mobigate.DATA_GATHER_POLICY_HIDE_TRAY
•	Mobigate.DATA_GATHER_POLICY_BLOCK_DATA_BG
4.3 Data collectors constants
Used to set which data the library should collect:
•	Mobigate.DATA_COLLECTOR_APPS_LIST
•	Mobigate.DATA_COLLECTOR_APPS_USAGE
•	Mobigate.DATA_COLLECTOR_BATTERY
•	Mobigate.DATA_COLLECTOR_BROWSER
•	Mobigate.DATA_COLLECTOR_CALENDAR_EVENTS
•	Mobigate.DATA_COLLECTOR_CPU_PROCESS
•	Mobigate.DATA_COLLECTOR_DICTIONARY
•	Mobigate.DATA_COLLECTOR_GEOLOCATION
•	Mobigate.DATA_COLLECTOR_HEADSET_PLUG
•	Mobigate.DATA_COLLECTOR_MEDIA_FILES
•	Mobigate.DATA_COLLECTOR_MEMORY_USEAGE
•	Mobigate.DATA_COLLECTOR_NETWORK_CONNECTION
•	Mobigate.DATA_COLLECTOR_NETWORK_USEAGE
•	Mobigate.DATA_COLLECTOR_PACKAGE_CHANGE
•	Mobigate.DATA_COLLECTOR_PHONE_INFO
•	Mobigate.DATA_COLLECTOR_ROAMING
•	Mobigate.DATA_COLLECTOR_SCREEN_ORIENTED
•	Mobigate.DATA_COLLECTOR_SIGNAL_STRENGTH
•	Mobigate.DATA_COLLECTOR_PROFILE_MODE
•	Mobigate.DATA_COLLECTOR_WIFI_DATA_CONNECTION
•	Mobigate.DATA_COLLECTOR_PERMISSION_COLLECTOR
•	Mobigate.DATA_COLLECTOR_NFC_COLLECTOR
•	Mobigate.DATA_COLLECTOR_BLUETOOTH_COLLECTOR
•	Mobigate.DATA_COLLECTOR_BLUETOOTH_DEVICES_COLLECTOR
•	Mobigate.DATA_COLLECTOR_MOVEMENT_COLLECTOR
•	Mobigate.DATA_COLLECTOR_FACEBOOK_NETWORK_COLLECTOR
•	Mobigate.DATA_COLLECTOR_ROOT_COLLECTOR
4.4 Category and parameter constants
Instead of using defined categories or parameters in the form of text, you can use constants defined in the plugin. All you have to do is add the prefix "CATEGORY_" or "PARAMETER_" to the category name or parameter e.g., Mobigate.CATEGORY_LEVEL_ACCOMPLISHED, Mobigate.CATEGORY_PURCHASE, Mobigate.PARAMETER_PRICE, Mobigate.PARAMETER_LEVEL.
5. Sample app
The sample application is located in the github repository here in example folder.