Flutter SDK Full Reference

initSession

Method

Description

Stream<Map<dynamic, dynamic>> initSession()

Initiates a session with the Branch API through a listener.

Example Usage
streamSubscription = FlutterBranchSdk.initSession().listen((data) {
  print('listenDynamicLinks - DeepLink Data: $data');
  controllerData.sink.add((data.toString()));
  if (data.containsKey('+clicked_branch_link') &&
      data['+clicked_branch_link'] == true) {
    print(
      '------------------------------------Link clicked----------------------------------------------');
    print('Custom string: ${data['custom_string']}');
    print('Custom number: ${data['custom_number']}');
    print('Custom bool: ${data['custom_bool']}');
    print('Custom list number: ${data['custom_list_number']}');
    print(
      '------------------------------------------------------------------------------------------------');
    showSnackBar(
      context: context,
      message: 'Link clicked: Custom string - ${data['custom_string']}',
      duration: 10);
  }
}, onError: (error) {
  PlatformException platformException = error as PlatformException;
  print(
    'InitSession error: ${platformException.code} - ${platformException.message}');
  controllerInitSession.add(
    'InitSession error: ${platformException.code} - ${platformException.message}');
});

validateSDKIntegration

Method

Description

void validateSDKIntegration()

Use the SDK integration validator to check that you've added the Branch SDK and handle deep links correctly when you first integrate Branch into your app. Validates the following:

  • Branch Keys
  • Package Name
  • URI Schemes
  • Android App Link
  • Universal Links
  • Link Domains

Example Usage:

FlutterBranchSdk.validateSDKIntegration();

setRequestMetadata

Method

Description

void setRequestMetadata(String key, String value)

Sets specific key/value pairs to all requests. This is required for integrating with specific partners like Adobe Analytics, Amplitude, etc. Partner keys can be found in the partner-specific guides.

Argument

Type

Description

key

String

The partner key. Ex. $marketing_cloud_visitor_id

value

String

The value of the partner key

Example Usage

FlutterBranchSdk.setRequestMetadata(requestMetadataKey, requestMetadataValue);

setIdentity

Method

Description

void setIdentity(String userId)

Sets the identity of a user (email, ID, UUID, etc) for events, deep links, and referrals. Use this method when the user logs into their account in your app.

See PII Best Practices for details.

Argument

Type

Description

userId

String

The unique ID of the user

Example Usage

FlutterBranchSdk.setIdentity('user1234567890');

isUserIdentified

Method

Description

Future<bool> isUserIdentified()

Indicates whether or not this user has a custom identity specified for them. Note that this is independent of installs.

If you call the setIdentity method, this device will have that identity associated with this user until the logout method is called.

This includes persisting through uninstalls, as device ID is tracked.

Example Usage

bool isUserIdentified = await FlutterBranchSdk.isUserIdentified();

logout

Method

Description

void logout()

Clears the identity set from the setIdentity() method. This method should be called if you know that the user is explicitly logging out or if a different person is about to use the app.

Example Usage

FlutterBranchSdk.logout();

getLatestReferringParams

Method

Description

Future<Map<dynamic, dynamic>> getLatestReferringParams()

Returns the last parameters associated with the link that referred the user to the current app session.

Example Usage

Map<dynamic, dynamic> params = await FlutterBranchSdk.getLatestReferringParams();

getFirstReferringParams

Method

Description

Future<Map<dynamic, dynamic>> getFirstReferringParams()

Returns the first parameters associated with the link that referred the user. Consider this as the parameters used to retrieve the details from the user's first app session.

Example Usage

ap<dynamic, dynamic> params = await FlutterBranchSdk.getFirstReferringParams();

disableTracking

Method

Description

void disableTracking(bool value)void disableTracking(bool value)

If you need to comply with a user's request to not be tracked for GDPR purposes, or otherwise determine that a user should not be tracked, utilize this method to prevent Branch from sending network requests. This setting can also be enabled across all users for a particular link or across your Branch Links.

Argument

Type

Description

value

Boolean

If set to true, disableTracking is enabled.
If set to false, disableTracking is disabled.

Example Usage

FlutterBranchSdk.disableTracking(true);

getShortUrl

Argument

Type

Description

buo

BranchUniversalObject

The Universal Object used to define content within your app.

BUO Best Practices

linkProperties

BranchLinkProperties

The analytics properties associated with the link you are about to generate.

Example Usage

BranchUniversalObject buo = BranchUniversalObject(
  canonicalIdentifier: 'flutter/branch',
  //canonicalUrl: '',
  title: 'Flutter Branch Plugin',
  imageUrl: 'https://flutter.dev/assets/flutter-lockup-4cb0ee072ab312e59784d9fbf4fb7ad42688a7fdaea1270ccf6bbf4f34b7e03f.svg',
  contentDescription: 'Flutter Branch Description',
  keywords: ['Plugin', 'Branch', 'Flutter'],
  publiclyIndex: true,
  locallyIndex: true,
  contentMetadata: BranchContentMetaData()..addCustomMetadata('custom_string', 'abc')
  ..addCustomMetadata('custom_number', 12345)
  ..addCustomMetadata('custom_bool', true)
  ..addCustomMetadata('custom_list_number', [1,2,3,4,5 ])
  ..addCustomMetadata('custom_list_string', ['a', 'b', 'c']),
);

BranchLinkProperties lp = BranchLinkProperties(
  //alias: 'flutterplugin', //define link url,
  channel: 'facebook',
  feature: 'sharing',
  stage: 'new share',
  tags: ['one', 'two', 'three']
);
lp.addControlParam('url', 'http://www.google.com');
lp.addControlParam('url2', 'http://flutter.dev');

BranchResponse response =
  await FlutterBranchSdk.getShortUrl(buo: buo, linkProperties: lp);
if (response.success) {
  print('Link generated: ${response.result}');
} else {
  print('Error : ${response.errorCode} - ${response.errorMessage}');
}

showShareSheet

Argument

Type

Description

buo

BranchUniversalObject

The Universal Object used to define content within your app.

BUO Best Practices

linkProperties

BranchLinkProperties

The analytics properties associated with the link you are about to generate.

messageText

String

The body of the message in your share sheet.

androidMessageTitle

String

The message title of the share sheet.

androidSharingTitle

String

The sharing title of the share sheet.

Example Usage

BranchResponse response = await FlutterBranchSdk.showShareSheet(
  buo: buo,
  linkProperties: lp,
  messageText: 'My Share text',
  androidMessageTitle: 'My Message Title',
  androidSharingTitle: 'My Share with');

if (response.success) {
  print('showShareSheet Sucess');
} else {
  print('Error : ${response.errorCode} - ${response.errorMessage}');
}

trackContent

Method

Description

void trackContent({required List<BranchUniversalObject> buo, required BranchEvent branchEvent})

Logs a Branch Event for tracking and analytics. It is recommended to be tracking Standard Events, but you have the ability to track Custom Events as well.

Additional details on event tracking here.

Argument

Type

Description

buo

List<BranchUniversalObject

A list of Universal Objects used to define content within your app.

BUO Best Practices

branchEvent

BranchEvent

The event that you are tracking.

Example Usage

BranchEvent eventStandart = BranchEvent.standardEvent(BranchStandardEvent.ADD_TO_CART);
eventStandart.transactionID = '12344555';
eventStandart.currency = BranchCurrencyType.BRL;
eventStandart.revenue = 1.5;
eventStandart.shipping = 10.2;
eventStandart.tax = 12.3;
eventStandart.coupon = 'test_coupon';
eventStandart.affiliation = 'test_affiliation';
eventStandart.eventDescription = 'Event_description';
eventStandart.searchQuery = 'item 123';
eventStandart.adType = BranchEventAdType.BANNER;
eventStandart.addCustomData(
  'Custom_Event_Property_Key1', 'Custom_Event_Property_val1');
eventStandart.addCustomData(
  'Custom_Event_Property_Key2', 'Custom_Event_Property_val2');

FlutterBranchSdk.trackContent(buo: [buo], branchEvent: eventStandart);

//tracking event as a custom event
BranchEvent eventCustom = BranchEvent.customEvent('Custom_event');
FlutterBranchSdk.trackContentWithoutBuo(branchEvent: eventCustom);

trackContentWithoutBuo

Method

Description

void trackContentWithoutBuo({required BranchEvent branchEvent})

Logs a Branch Event for tracking and analytics without a Universal Object. It is recommended to be tracking Standard Events, but you have the ability to track Custom Events as well.

Additional details on event tracking here.

Argument

Type

Description

branchEvent

BranchEvent

The event that you are tracking.

Example Usage

BranchEvent eventStandart = BranchEvent.standardEvent(BranchStandardEvent.ADD_TO_CART);
FlutterBranchSdk.trackContentWithoutBuo(branchEvent: eventStandart);

registerView

Method

Description

void registerView({required BranchUniversalObject buo})

Mark the content referred to by this object as viewed. This will increment the view count of the contents referred by this object.

Argument

Type

Description

buo

BranchUniversalObject

The Universal Object used to define content within your app.

BUO Best Practices

Example Usage

FlutterBranchSdk.registerView(buo: buo);

listOnSearch

Method

Description

Future<bool> listOnSearch( {required BranchUniversalObject buo, BranchLinkProperties? linkProperties})

For Android:

  • Publishes the Universal Object with Google App Indexing so that the contents will be available with Google Search

For iOS:

  • List items on Spotlight

Argument

Type

Description

buo

BranchUniversalObject

The Universal Object used to define content within your app.

BUO Best Practices

linkProperties

BranchLinkProperties

The analytics properties associated with the link you are about to generate.

Example Usage

bool success = await FlutterBranchSdk.listOnSearch(buo: buo);
print(success);

removeFromSearch

Method

Description

Future<bool> removeFromSearch( {required BranchUniversalObject buo, BranchLinkProperties? linkProperties})

For Android:

  • Remove the BUO from the local indexing if it is added to the local indexing already.
  • Remove the content from Google (Firebase) and other supported indexing services

For iOS:

  • Remove the BUO from Spotlight if privately indexed

Argument

Type

Description

buo

BranchUniversalObject

The Universal Object used to define content within your app.

BUO Best Practices

linkProperties

BranchLinkProperties

The analytics properties associated with the link you are about to generate.

Example Usage

bool success = await FlutterBranchSdk.removeFromSearch(buo: buo);
print('Remove sucess: $success');

setIOSSKAdNetworkMaxTime

Method

Description

void setIOSSKAdNetworkMaxTime(int hours)

Sets the time window for SKAdNetwork callout in hours. iOS ONLY.

By default, Branch limits calls to SKAdNetwork to within 72 hours after first install.

Argument

Type

Description

hours

int

Time window in hours.

Example Usage

FlutterBranchSdk.setIOSSKAdNetworkMaxTime(24);


requestTrackingAuthorization

Method

Description

Future<AppTrackingStatus> requestTrackingAuthorization()

Requests AppTracking Authorization and returns AppTrackingStatus. iOS ONLY

Example Usage

AppTrackingStatus status = await FlutterBranchSdk.requestTrackingAuthorization();
print(status);

getTrackingAuthorizationStatus

Method

Description

Future<AppTrackingStatus> getTrackingAuthorizationStatus()

Returns AppTrackingStatus. iOS ONLY

Example Usage

AppTrackingStatus status = await FlutterBranchSdk.getTrackingAuthorizationStatus();
print(status);

getAdvertisingIdentifier

Method

Description

Future<String> getAdvertisingIdentifier()

Returns the advertising identifier. iOS ONLY

Example Usage

String status = await FlutterBranchSdk.getAdvertisingIdentifier();
print(status);

Did this page help you?