flutter-branch-io

Flutter plugin implemented Branch IO's SDK to Flutter.

Currently only supported Android, still need to work on iOS's swift side.

Implemented function:

  • Initialization and get Deep Link data to a subscribe-able stream on dart.
  • Create BUO and MetaData model
  • Generate new deeplink and get the link
  • List BUO on google search
  • Track content & evnt
  • Track user by id

HOW TO USE

  • Import flutter_branch_io_plugin to your pubspec.yaml

  • Change these setups in your AndroidManifest.xml

    • Open your MainActivity and import com.anggach.flutterandroidlifecycle.FlutterAndroidLifecycleActivity

    • Change the MainActivity class to extend FlutterBranchIOActivity

    • Add this inside your AndroidManifest.xml (inside activity tag, after the Main and Launcher intent-filter)

            <!-- Branch URI scheme -->
            <intent-filter>
                <data android:scheme="YOURSCHEME" android:host="open"/>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
      
            <!-- Branch App Links -->
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" android:host="YOURHOST.test-app.link" />
            </intent-filter>
      

    Where YOURSCHEME is the Deep Link Scheme you setup at Branch.io dashboard, and YOURHOST is the Deep Link Host you setup at the dashboard

    • And add this inside application, (right after )

            <!-- Branch init -->
            <meta-data android:name="io.branch.sdk.BranchKey" android:value="YOURLIVEKEY" />
            <meta-data android:name="io.branch.sdk.BranchKey.test" android:value="YOURTESTKEY" />
            <meta-data android:name="io.branch.sdk.TestMode" android:value="true" /> <!-- Set to true to use Branch_Test_Key -->
      
            <!-- Branch install referrer tracking -->
            <receiver android:name="io.branch.referral.InstallListener" android:exported="true">
                <intent-filter>
                    <action android:name="com.android.vending.INSTALL_REFERRER" />
                </intent-filter>
            </receiver>
      

      Where YOURLIVEKEY is your Branch.io live key, and YOURTESTKEY is your Branch.io test key.

    • Last, you need to call this code inside your application's initState

          FlutterBranchIoPlugin.setupBranchIO();
          FlutterBranchIoPlugin.listenToDeepLinkStream().listen((string) {
            print("DEEPLINK $string");
            setState(() {
              this._data = string;
            });
          });
          FlutterAndroidLifecycle.listenToOnStartStream().listen((string) {
            print("ONSTART");
            FlutterBranchIoPlugin.setupBranchIO();
          });
    

Functions

  • To generate new deep link from flutter, you can use this

First, you need to subscribe to the generated link stream, which will produce the generated link after you created a link from a branch universal object


    FlutterBranchIoPlugin.listenToGeneratedLinkStream().listen((link) {
          print("GET LINK IN FLUTTER");
          print(link);
          setState(() {
            this.generatedLink = link;
          });
        });

Then, you can start generate new links based on any Branch Universal Object you pass, and you can also add some Link Properties inside


    FlutterBranchIoPlugin.generateLink(
          FlutterBranchUniversalObject()
              .setCanonicalIdentifier("content/12345")
              .setTitle("My Content Title")
              .setContentDescription("My Content Description")
              .setContentImageUrl("https://lorempixel.com/400/400")
              .setContentIndexingMode(BUO_CONTENT_INDEX_MODE.PUBLIC)
              .setLocalIndexMode(BUO_CONTENT_INDEX_MODE.PUBLIC),
          lpChannel: "facebook",
          lpFeature: "sharing",
          lpCampaign: "content 123 launch",
          lpStage: "new user",
          lpControlParams: {
            "url": "http://www.google.com"
          }
        );
  • Track Content to track content, you can create a new branch universal object and some event identifier (String)
    FlutterBranchIoPlugin.trackContent( FlutterBranchUniversalObject()
            .setCanonicalIdentifier("content/12345")
            .setTitle("My Content Title")
            .setContentDescription("My Content Description")
            .setContentImageUrl("https://lorempixel.com/400/400")
            .setContentIndexingMode(BUO_CONTENT_INDEX_MODE.PUBLIC)
            .setLocalIndexMode(BUO_CONTENT_INDEX_MODE.PUBLIC), FlutterBranchStandardEvent.VIEW_ITEM);
  • Set User ID to set user id for current session, you can use
    FlutterBranchIoPlugin.setUserIdentity(USER_ID)
  • Clear User ID to clear user id for current session, you can use
    FlutterBranchIoPlugin.clearUserIdentity()
  • List Universal Object on Google Search to list an universal object on google search, you can use
    FlutterBranchIoPlugin.listOnGoogleSearch(
              FlutterBranchUniversalObject()
                  .setCanonicalIdentifier("content/12345")
                  .setTitle("My Content Title")
                  .setContentDescription("My Content Description")
                  .setContentImageUrl("https://lorempixel.com/400/400")
                  .setContentIndexingMode(BUO_CONTENT_INDEX_MODE.PUBLIC)
                  .setLocalIndexMode(BUO_CONTENT_INDEX_MODE.PUBLIC),
              lpChannel: "facebook",
              lpFeature: "sharing",
              lpCampaign: "content 123 launch",
              lpStage: "new user",
              lpControlParams: {
                "url": "http://www.google.com"
              }
            );

Version

  • 0.0.1 Initial upload
  • 0.0.1+2 Add Swift dependencies and version

Contributor

  • Angga Dwi Arifandi (angga.dwi@oval.id)
  • Abdul Ghapur (gofur@oval.id)

Libraries

flutter_branch_io_plugin

Dart

dart:ui
Built-in types and core primitives for a Flutter application. [...]

Core

dart:async
Support for asynchronous programming, with classes such as Future and Stream. [...]
dart:collection
Classes and utilities that supplement the collection support in dart:core. [...]
dart:convert
Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
dart:core
Built-in types, collections, and other core functionality for every Dart program. [...]
dart:developer
Interact with developer tools such as the debugger and inspector. [...]
dart:math
Mathematical constants and functions, plus a random number generator. [...]
dart:typed_data
Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]

VM

dart:io
File, socket, HTTP, and other I/O support for non-web applications. [...]
dart:isolate
Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]