SDK Integration - Flutter integration 

Page / - last modified by Developer on 2020/03/19 15:15 

Flutter integration 
last modified by Developer
on 2020/03/19 15:15

Table of Contents
1. Overview
2. Adding SDK to the project
3. Api methods
3.1 MobigateSDK class initialization
3.2 SDK initialization
3.3 Tracking in app events
3.3.1 Overview
3.3.2 Implementation
3.3.3 Event categories
3.3.4 Event parameters
3.4 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 MobigateSDK class initialization
•	3.2 SDK initialization
•	3.3 Tracking in app events
•	3.3.1 Overview
•	3.3.2 Implementation
•	3.3.3 Event categories
•	3.3.4 Event parameters
•	3.4 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 pub repositories (pub repositories)
This plugin is built for:
•	Mobigate SDK version 1.0.6
2. Adding SDK to the project
First, add this to your package's pubspec.yaml file
dependencies:
  flutter_mobigate: ^1.0.2
Install packages from the command line
$ flutter pub get
3. Api methods
To use any method from the plugin add import:
import 'package:flutter_mobigate/flutter_mobigate.dart';
3.1 MobigateSDK class initialization
Initialize class with MobigateSDK(MobigateOptions options)
MobigateOptions(apiKey,{appIdentifier, appInstallationSource,email,cusUserId,enableUserFields,dataGatherPolicy,notificationText,enableIdProfiles})
MobigateOptions

Name	Type	Default	Description	
 appIdentifier	String	 	 Application identifier	
appInstallationSource 	String	 	 App installation source e.g., google-play, organic.	
email 	String 	 	 Set's user email.	
cusUserId 	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.	
 notificationText	String 	 	  if state = Mobigate.DATA_GATHER_POLICY_DEFAULT you can pass custom foreground service notification text.	
 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	

Example

  MobigateSDK mobigateInstance = MobigateSDK(MobigateOptions(
     "V0K6jhiIfem6CRWHYZ59Nmj3oFBBKbJsnSsWfR2JNq7ktblOUXwbJoBQTpWnw2uSwW76gpiu2kun50jweTY69B"
  ));

3.2 SDK initialization
You must initialize the library before running it. Use Future<String> init method for that:
mobigateInstance.init()
Return:
Message	Type	Description	
success	String	returns success message	
error	String	returns error message	
When the library is already initialized run it. Use Future<String> startSdk() method for that:
mobigateInstance.startSdk(); 
Return:
Message	Type	Description	
success	String	returns success message	
error	String	returns error message	
3.3 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.3.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, flutter_mobigate plugin contains recommended event categories and parameters via String constants (see Event categories and Event parameters).
3.3.2 Implementation
Tracking in-app events is performed by two methods:
void trackEvent(Category category) 
Parameter	Type	Description	
Category	Category class 	Category class built with help of CategoryBuilder	
Example

mobigateInstance.trackEvent((CategoryBuilder(EventCategory.BEGIN_TRIAL)
    ..setParameter(EventParameter.CITY, "Warsaw")
    ..setParameter(EventParameter.CONTENT_ID, 523456)
    ..setParameter(EventParameter.COUPON_CODE, 97636572)
    ..setParameter(EventParameter.CUSTOMER_SEGMENT, [1, 2, 4]))
  .build());

void trackAppInstall(int timestamp)
Parameter	Type	Description	
timestamp	double	Unix timestamp in milliseconds	
Example

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

3.3.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.3.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.4 Remaining methods
void setCollectAll()
This method enables all data collectors. By default all data collectors are enabled.
Example

mobigateInstance.setCollectAll();

void configureDataCollectors(bool enable, List<int> 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

mobigateInstance.configureDataCollectors(true, [
          DataCollector.APPS_LIST,
          DataCollector.APPS_USAGE,
          DataCollector.BROWSER
        ]);

void disableAllDataCollector()
Disable all data collectors
Example

mobigateInstance.disableAllDataCollector();

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

mobigateInstance.setEmail('test@spicymobile.pl');

Future<String> getEmail()
Get previously set user email. Return email on success, error otherwise.
Example

final String email = await mobigateInstance.getEmail();

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

mobigateInstance.setFbToken('dsf87esy789fys9dfu08sds54s6547c8s8doc4');

Future<String> getSDKInfo()
Getting information about the library. Return on success sdk info string, error otherwise.
Example

final String sdkInfo = await mobigateInstance.getSDKInfo();

Future<String> getSDKUniqueIdentifier()
Return unique SDK identificator. Return on success sdk unique identifier, error otherwise.
Example

final String sdkUniqueIdentifier = await mobigateInstance.getSDKUniqueIdentifier();

Future<List<int>> getIDsProfiles()
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
Example

final List<int> idsProfiles = await mobigateInstance.getIDsProfiles();

Future<Map<String, int>> getAdOceanTargeting()
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
Example

final Map<String,int> adOceanTargeting = await mobigateInstance.getAdOceanTargeting();

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:
•	UserField.USER_FIELD_EMAIL
•	UserField.USER_FIELD_IMSI
•	UserField.USER_FIELD_IMEI
•	UserField.USER_FIELD_SERIAL
4.2 Data gather policy constants
Used to set how the library collects data:
•	MonitorState.DATA_GATHER_POLICY_DEFAULT
•	MonitorState.DATA_GATHER_POLICY_HIDE_TRAY
•	MonitorState.DATA_GATHER_POLICY_BLOCK_DATA_BG
4.3 Data collectors constants
Used to set which data the library should collect:
•	DataCollector.APPS_LIST
•	DataCollector.DATA_COLLECTOR_APPS_USAGE
•	DataCollector.BATTERY
•	DataCollector.BROWSER
•	DataCollector.CALENDAR_EVENTS
•	DataCollector.CPU_PROCESS
•	DataCollector.DICTIONARY
•	DataCollector.GEOLOCATION
•	DataCollector.HEADSET_PLUG
•	DataCollector.MEDIA_FILES
•	DataCollector.MEMORY_USEAGE
•	DataCollector.NETWORK_CONNECTION
•	DataCollector.NETWORK_USEAGE
•	DataCollector.PACKAGE_CHANGE
•	DataCollector.PHONE_INFO
•	DataCollector.ROAMING
•	DataCollector.SCREEN_ORIENTED
•	DataCollector.SIGNAL_STRENGTH
•	DataCollector.PROFILE_MODE
•	DataCollector.WIFI_DATA_CONNECTION
•	DataCollector.PERMISSION_COLLECTOR
•	DataCollector.NFC_COLLECTOR
•	DataCollector.BLUETOOTH_COLLECTOR
•	DataCollector.BLUETOOTH_DEVICES_COLLECTOR
•	DataCollector.MOVEMENT_COLLECTOR
•	DataCollector.FACEBOOK_NETWORK_COLLECTOR
•	DataCollector.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 use EventCategory or EventParameter class e.g., EventCategory.LEVEL_ACCOMPLISHED, EventCategory.PURCHASE, EventParameter.PRICE, EventParameter.LEVEL.
5. Sample app
The sample application is located in the github repository here in example folder.