RDC Flutter SDK

Overview

Development Kits (SDKs) for mobile devices named Rabbit Mobile SDK. The Rabbit Mobile SDK will be used for tagging and collecting online data from the mobile application of the Rabbit’s each business unit.

The SDK will be used to collect the online behavior transaction of all Rabbit customers across all its business units and developed into the data analysis and data science model and eventually will be used for data monetization.

Flow Chart

Flow Chart

Features

Rabbit Data Online Collection SDK for Flutter provides the following features.

In-line Configuration We will implement the overridable configuration by an in-line code configuration on the application bootstrap startup.

Caching The SDK will use cache manager as its in-memory cache to store a device’s static data and MongoDB Realm to keep the tracking data for later use.

Trigger to send data to the API backend Conditions before being sent to the API backend are checked for CPU, Memory, and Battery. All conditions to pass and SDK send data to the API backend.

Flow Chart

Flow Chart

Using the SDK

Prerequisites

  • iOS 12.0 or later.
  • Android 7.0 or later.
  • Flutter 2 or later.

Platform Support

Android iOS
✔️ ✔️

Install plugin

rdc_flutter_sdk: ^0.0.22
realm: ^1.0.0

Setup

Dart Setup

required use Plugin https://pub.dev/packages/permission_handler

await Permission.location.request(); // android, IOS
await Permission.appTrackingTransparency.request(); // IOS only

Android Setup

add lines below in AndroidManifest.xml file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> << add this line >>


build.gradle

allprojects {
    repositories {
        google()
        mavenCentral()

        //** add this line
        configurations.all {
            resolutionStrategy {
                force "com.google.android.gms:play-services-location:21.0.1"
            }
        }
    }
}

IOS Setup

Info.plist

<!-- Permission options for the `location` group -->

<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location when in use</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Always and when in use!</string>
<key>NSLocationUsageDescription</key>
<string>Older devices need location.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Can I have location always?</string>
<key>UIBackgroundModes</key>
<string>location</string>

<!-- Permission options for the `appTrackingTransparency` -->

<key>NSUserTrackingUsageDescription</key>
<string>appTrackingTransparency</string>

Podfile

##dart: PermissionGroup.appTrackingTransparency

'PERMISSION_APP_TRACKING_TRANSPARENCY=1',

##dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]

'PERMISSION_LOCATION=1',

Configuration

Method Params Remark
setAPIKey String key Authentication key
setEncryptionKey String key Encryption key for encryp data support only hive
setRotationTime int min = 1 Loop time for send data to API
setDataCollectionType DataCollectionType type = rotation Type send data to API immediately or loop
setRetentionDays int date = 30 Clear all data these sent to API
setDeleteAfterSent bool value = true Delete after sent or not.
setOfflineMode bool value = false Send data to API or not.
setRetryOnFailed int time = 3 Retries send data to API.
setTriggerCondition int cpu = 0, int memory = 0, int batteryLevel = 0 Condition for send data to API
setSessionExpire int min = 60 Session expire minute for forgeground
setSessionAutoExpire int min = 30 Session will end after inactive time
setConsent bool? value = null Consent from user
setPermissionMaid bool value = false User allow permission for get Maid only Android
setStorageCondition required int min, required int max Storage < min not save to local database and send API
Storage between min - max FIFO data in local database

Event Method

Method Params Remark
addEvent {required String eventName, required String eventValue, Map<dynamic, dynamic>? dataLayer} Add event log in local database
getEvents - Get list events in local database
uploadEvent - Upload list events send to API
clearAll - Delete all
clearCache - Delete only isSent
sessionStart - Start session in sdk
sessionEnd - End session in sdk

Custom Data Layer

The limitation is that it must be flat JSON only and All object have to varchar type

addEvent(dataLayer: {
    'custom_field_1': 'custom_field_1',
    'custom_field_2': 'custom_field_2',
});

Example

Future<void> main() async {

    WidgetsFlutterBinding.ensureInitialized();

    await Permission.location.request();
    await Permission.appTrackingTransparency.request();

    var config = RabbitDataConfig(
        apiKey: 'aStdsdJsskdjaolsdYUSsdsdSDijsdkjwe',   // required
        collectionType: DataCollectionType.event,       // default
        rotationTime: 1,                                // default
        retentionDays: 30,                              // default
        retryTime: 3,                                   // default
        deleteAfterSent: true,                          // default
        cpu: 90,                                        // default
        memory: 80,                                     // default
        betteryLevel: 30,                               // default
        dbType: DBType.hive,                            // default if you usege flutter version > 3 you can use both of hive and realm database.
        consent: null,                                  // default
        permissionMaid: false,                          // default
        sessionExpire: con.sessionExpireMin,            // default
        sessionAutoExpire: con.autoExpireMin,           // default
        offlineMode: true,                              // default
        storageMin: 1,                                  // default
        storageMax: 5                                   // default
        isAutoExpire: true,                             // default
        locationTimeout: 3                              // default
        );
    var rabbitData = await RabbitData.initializeInstance(config);

    await rabbitData.addEvent('init_app', 'init_app');

    runApp(MyApp());

}

Realm Flutter SDK Reference

if usege flutter < version 2 please config RabbitDataConfig(dbType: DBType.hive) only

if usege flutter > version 3 you can use both RabbitDataConfig(dbType: DBType.hive) or RabbitDataConfig(dbType: DBType.realm)

https://pub.dev/packages/realm

Environment setup for Realm Flutter
Supported platforms are Flutter (iOS, Android, Windows, MacOS) and Dart standalone (Windows, MacOS and Linux)

Flutter ^3.0

For Flutter Desktop environment setup check the guide here

Cocoapods v1.11 or newer

CMake 3.21 or newer

Trying the example app

  1. Clone the repository. git clone https://bitbucket.org/bssh-rabbit/rdc-flutter-sdk/src/master/example

  2. Open the Folder file in Vscode or Android Studio.

  3. Cmd the flutter run in terminal.

The example app should launch.

Libraries

rabbit_data