initSession (Deprecated)
Method | Description |
---|---|
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 |
---|---|
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:
|
Example Usage:
FlutterBranchSdk.validateSDKIntegration();
setRequestMetadata
Method | Description |
---|---|
Set 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 |
---|---|---|
|
| The partner key. Ex. |
|
| The value of the partner key |
Example Usage
FlutterBranchSdk.setRequestMetadata(requestMetadataKey, requestMetadataValue);
setIdentity
Method | Description |
---|---|
Set the identity of a user (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 |
---|---|---|
|
| The unique ID of the user |
Example Usage
FlutterBranchSdk.setIdentity('user1234567890');
isUserIdentified
Method | Description |
---|---|
Indicate whether or not this user has a custom identity specified for them. Note that this is independent of installs.If you call the |
Example Usage
bool isUserIdentified = await FlutterBranchSdk.isUserIdentified();
logout
Method | Description |
---|---|
Clear the identity set from the |
Example Usage
FlutterBranchSdk.logout();
handleDeepLink
Method | Description |
---|---|
End the current deep link session and starts a new session with the provided URL. |
Argument | Type | Description |
---|---|---|
|
| The URL of the deep link for the new session. |
Example Usage
FlutterBranchSdk.handleDeepLink('myapp://open?link_click_id=12345');
getLatestReferringParams
Method | Description |
---|---|
Return 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 |
---|---|
Return 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
Map<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 |
---|---|---|
|
| If set to |
Example Usage
FlutterBranchSdk.disableTracking(true);
getShortUrl
Method | Description |
---|---|
Generate a Branch Short Link used for deep linking and attribution. |
Argument | Type | Description |
---|---|---|
|
| The Universal Object used to define content within your app.BUO Best Practices |
|
| 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
Method | Description |
---|---|
Display a share sheet to prompt the user to share to an external platform (ex. messaging) |
Argument | Type | Description |
---|---|---|
|
| The Universal Object used to define content within your app. BUO Best Practices |
|
| The analytics properties associated with the link you are about to generate. |
|
| The body of the message in your share sheet. |
|
| The message title of the share sheet. |
|
| 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}');
}
getQRCode
Method | Description |
---|---|
Method | |
Method |
Argument | Type | Description |
---|---|---|
|
| Color name or Hex color value |
|
| Color name or Hex color value of the background of the QR code itself. |
|
| The number of pixels you want for the margin. Min 1px. Max 20px. |
|
| Output size of QR Code image. Min 300px. Max 2000px. (Only applicable to JPEG/PNG) |
|
| JPEG, PNG |
|
| URL to the image you want as a center logo e.g. https://cdn.us.document360.io/082e8be0-ad38-4650-9062-689a75e517a2/Images/Documentation/branch%20logo%20qrcode.jpeg |
Example Usage
BranchResponse responseQrCodeImage = await FlutterBranchSdk.getQRCodeAsImage(
buo: buo!,
linkProperties: lp,
qrCode: BranchQrCode(primaryColor: Colors.black,
//primaryColor: const Color(0xff443a49), //Hex colors
centerLogoUrl: imageURL,
backgroundColor: Colors.white,
imageFormat: BranchImageFormat.PNG));
if (response.success) {
print('QrCode Success');
showQrCode(this.context, responseQrCodeImage.result);
/*
Image(image: responseQrCodeImage.result,
height: 250,
width: 250,),
*/
} else {
print('Error : ${response.errorCode} - ${response.errorMessage}');
trackContent
By default, the Branch SDK tracks clicks, opens, installs, reinstalls and impressions automatically (out-of-the-box).
General Event Tracking
Please refer to our Event Tracking Docs for more information and examples:
Tracking In-App Web View Events
With the Branch Flutter SDK, it is possible to inject JavaScript into an in-app web view with event listeners to make calls to one of our mobile SDKs.
In this scenario, the website’s JavaScript posts a message when a button or element on the page is clicked. The app then uses a JavaScript channel to listen for that message. Inside of the callback, a switch statement is used to check the message and trigger a Branch Event.
To implement this approach:
Add JavaScript code to the website to add a listener to the button’s selector and call the
postMessage()
function:var _selector = document.querySelector('button[id=BUTTON_ID]'); _selector.addEventListener('click', function(event) { var message = "LOGIN"; if (messageHandler) { messageHandler.postMessage(message); } });
Add a JavaScript channel to the WebViewController to handle the
onMessageRecieved
callback and trigger the corresponding Branch Event:class _MyWebViewState extends State {="" late="" final="" webviewcontroller="" controller;="" @override="" void="" initstate()="" {="" super.initstate();="" controller="WebViewController()" ..loadrequest(="" uri.parse('https://your_website.com'),="" );="" controller.setjavascriptmode(javascriptmode.unrestricted);="" controller.addjavascriptchannel('messagehandler',="" onmessagereceived:="" (message)="" {="" switch="" (message.message)="" {="" case="" "login":="" branchevent="" event="BranchEvent.standardEvent(BranchStandardEvent.LOGIN);" flutterbranchsdk.trackcontentwithoutbuo(branchevent:="" event);="" break;="" case="" "purchase":="" branchevent="" event="BranchEvent.standardEvent(BranchStandardEvent.PURCHASE);" flutterbranchsdk.trackcontentwithoutbuo(branchevent:="" event);="" break;="" }="" });="" }="" }="">>
registerView
Method | Description |
---|---|
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 |
---|---|---|
|
| The Universal Object used to define content within your app.BUO Best Practices |
Example Usage
FlutterBranchSdk.registerView(buo: buo);
listOnSearch
Method | Description |
---|---|
On iOS, list items on Spotlight. |
Argument | Type | Description |
---|---|---|
|
| The Universal Object used to define content within your app. BUO Best Practices |
|
| 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 |
---|---|
On iOS, remove the BUO from Spotlight if privately indexed. |
Argument | Type | Description |
---|---|---|
|
| The Universal Object used to define content within your app.BUO Best Practices |
|
| 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 |
---|---|
Set the time window for SKAdNetwork callout in hours on iOS only. |
Argument | Type | Description |
---|---|---|
|
| Time window in hours. |
Example Usage
FlutterBranchSdk.setIOSSKAdNetworkMaxTime(24);
requestTrackingAuthorization
Method | Description |
---|---|
Request AppTracking Authorization and returns AppTrackingStatus on iOS only. |
Example Usage
AppTrackingStatus status = await FlutterBranchSdk.requestTrackingAuthorization();
print(status);
getTrackingAuthorizationStatus
Method | Description |
---|---|
Return AppTrackingStatus on iOS only. |
Example Usage
AppTrackingStatus status = await FlutterBranchSdk.getTrackingAuthorizationStatus();
print(status);
getAdvertisingIdentifier
Method | Description |
---|---|
Return the advertising identifier on iOS only. |
Example Usage
String status = await FlutterBranchSdk.getAdvertisingIdentifier();
print(status);