rokt_sdk

The Rokt Flutter SDK enables you to integrate Rokt into your native mobile apps to drive more value from—and for—your customers.

The Rokt SDK for Flutter applications can be used by Rokt partners to display overlay or embedded placements, or by Rokt advertisers to record conversions for campaigns.

Resident Experts

Environment Build
release CircleCI

Usage

To use this plugin, add following code in your pubspec.yaml file.

dependencies:
  flutter:
    sdk: flutter

  rokt_sdk: ^4.0.0-alpha.3

Getting Started

Android

  1. Set the minSdkVersion and enable multidex in android/app/build.gradle:
android {
defaultConfig {
minSdkVersion 21
multidexEnabled true

    }
}

This means that app will only be available for users that run Android SDK 21 or higher.

  1. Include appcompat dependency implementation 'androidx.appcompat:appcompat:x.x.x’ The theme of android/app should extend from AppCompat Theme family, example:

    <style name="NormalTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"/>

iOS

Rokt iOS SDK supports iOS version 10 and above

How to update the SDK

_ Run flutter clean

  • Delete /ios/Pods
  • Delete /ios/Podfile.lock
  • Run flutter pub get
  • From inside ios folder, run pod install (or arch -x86_64 pod install for M1 Mac users)

Initializing the Rokt SDK

Initialize the Rokt SDK prior to using it. We recommend calling the initi method in the beginning of the applications.

// The following will reveal a demo integration. To view your integration:
// 1) Replace the integration test tag ID (222) with your unique Rokt Tag ID
// 2) Replace 1.0.0 with the application version
RoktSdk.initialize('222', appVersion: '1.0.0');

Overlay placements

Execute the Rokt iOS SDK in your desired view and add all appropriate customer attributes. The SDK provides optional callback events for when the view loads and unloads.

import 'package:rokt_sdk/rokt_sdk.dart';

void executeRokt() {
    // Replace RoktExperience with your viewName
    RoktSdk.execute(
                    viewName: "RoktExperience",
                    attributes: {"email": "j.smith@example.com",
                        "firstname": "Jenny",
                        "lastname": "Smith",
                        "mobile": "(555)867-5309",
                        "postcode": "90210",
                        "country": "US"},
                    onLoad: () {
                        // Optional callback for when the Rokt placement loads
                    },
                    onUnLoad: () {
                        // Optional callback for when the Rokt placement unloads
                    },
                    onShouldShowLoadingIndicator: () {
                        // Optional callback to show a loading indicator
                    },
                    onShouldHideLoadingIndicator: () {
                        // Optional callback to hide a loading indicator
                    });
}

To run an placement in the sandbox environment, the list of attributes passed to Rokt needs to be updated to include "sandbox": "true"

Embedded placements

add Rokt Widget

add const RoktWidget(placeholderName: "RoktEmbedded1") in your view. please make sure that the view is created on the visible area of the screen and then call showWidget. RoktWidget has a callback to notify when widget is created which could be utilized. RoktWidget(placeholderName: "RoktEmbedded1", onWidgetCreated: () { showWidget() })

Execute Rokt

import 'package:rokt_sdk/rokt_sdk.dart';

void showWidget() {
    // Replace RoktExperience with your viewName
    RoktSdk.execute(
                    viewName: "RoktExperience",
                    attributes: {"email": "j.smith@example.com",
                        "firstname": "Jenny",
                        "lastname": "Smith",
                        "mobile": "(555)867-5309",
                        "postcode": "90210",
                        "country": "US"},
                    onLoad: () {
                        // Optional callback for when the Rokt placement loads
                    },
                    onUnLoad: () {
                        // Optional callback for when the Rokt placement unloads
                    },
                    onShouldShowLoadingIndicator: () {
                        // Optional callback to show a loading indicator
                    },
                    onShouldHideLoadingIndicator: () {
                        // Optional callback to hide a loading indicator
                    });
}

To run an placement in the sandbox environment, the list of attributes passed to Rokt needs to be updated to include "sandbox": "true"

Requirements

Download Android Studio or VS Code for editor and install Flutter SDK

Requirements to integrate from versions 4.0.0 onwards include:

  • Kotlin version 1.8.0 or newer (e.g. ext.kotlin_version = '1.8.0')
  • Android Gradle plugin 7.4.0 or newer (e.g. com.android.tools.build:gradle:7.4.0)
  • Gradle version 7.5 or newer (e.g. distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip)

Project structure

This project consists of sdk Plugin which contains lib which is the main entry for the sdk plugin, android, iOS platform specific code for the sdk plugin and an example App which is a sample App to run the sdk plugin.

Publishing SDK

This SDK is published to pub.dev here. You can publish the alpha or prod package. To publish the package, you need to modify pubspec.yaml and update the version field. We should append -alpha after version if we intend to publish the alpha package. Make sure you add the changes in CHANGELOG.md. Publishing the package is possible through CircleCi or Buildkite by approving the hold_for_publish job.

How to manually publish sdk ?

  1. Make sure you have following environment variables set:
    PUB_DEV_PUBLISH_ACCESS_TOKEN=
    PUB_DEV_PUBLISH_REFRESH_TOKEN=
    PUB_DEV_PUBLISH_TOKEN_ENDPOINT=
    PUB_DEV_PUBLISH_EXPIRATION=
    
  2. Run following command
    cd .circleci
    ./pub_login.sh
    dart pub publish -f
    

Automated Publishing

The SDK can be released via the Mobile Release Pipeline. Follow the instructions in the Mobile Release Pipeline repo to release. You can still release the SDK manually by following the steps in the previous section.

How to manually run UI Test ?

UI test are located inside example app and you can run it by executing below command

flutter test integration_test/app_test.dart

How to run the example app locally

  • Open project in Android Studio for changing the code
  • Run following commands in terminal or equivalent in Android Studio
  • Run flutter clean
  • Run flutter pub get
  • Run flutter run

What are the branches?

There is one main branch with release- prefix. This branch is where all development branches are merged into. Publishing the package is possible with release- prefix branches only.

Update Rokt Native Sdk

To update the iOS rokt sdk, make the following changes.

   s.version          = 'X.X.X'
   s.dependency 'Rokt-Widget', '~> X.X.X'

For Android, do the folliwing

   implementation "com.rokt:roktsdk:X.X.X"

License

Copyright 2020 Rokt Pte Ltd

Licensed under the Rokt Software Development Kit (SDK) Terms of Use Version 2.0 (the "License");

You may not use this file except in compliance with the License.

Libraries

rokt_sdk