Initial SDK setup
Follow these instructions to install the Braze Flutter SDK that contains a package to allows integrators to use Braze APIs in Flutter apps written in Dart. This plugin provides basic analytics functionality and lets you integrate in-app messages and Content Cards for both iOS and Android with a single codebase.
You will need to complete installation steps on both platforms separately.
Prerequisites
To complete the installation, you will need the app identifier API key as well as the SDK endpoint. Both are located under Manage Settings in the dashboard.
Before following these steps, install and set up the Flutter SDK.
Step 1: Integrate the Braze library
Add the Braze Flutter SDK package from the command line.
1
flutter pub add braze_plugin
This will add the appropriate line to your pubspec.yaml
.
Step 2: Complete native setup
To connect to Braze servers, create a braze.xml
file in your project’s android/res/values
folder. Paste the following code and replace the API identifier key and endpoint with your values:
1
2
3
4
5
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="com_braze_api_key">YOUR_APP_IDENTIFIER_API_KEY</string>
<string translatable="false" name="com_braze_custom_endpoint">YOUR_CUSTOM_ENDPOINT_OR_CLUSTER</string>
</resources>
Add the required permissions to your AndroidManifest.xml
file:
1
2
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Add Appboy SDK import at the top of the AppDelegate.swift
file:
1
import Appboy_iOS_SDK
In the same file, add the following snippet within the application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
method and replace the API identifier key with your value:
1
Appboy.start(withApiKey: "YOUR-APP-IDENTIFIER-API-KEY", in:application, withLaunchOptions:launchOptions)
Add Appboy SDK import at the top of the AppDelegate.m
file:
1
#import "Appboy-iOS-SDK/AppboyKit.h"
In the same file, add the following snippet within the application:didFinishLaunchingWithOptions
method and replace the API identifier key with your value:
1
2
3
[Appboy startWithApiKey:@"YOUR-APP-IDENTIFIER-API-KEY"
inApplication:application
withLaunchOptions:launchOptions];
Then, add your SDK endpoint in the Info.plist
file. It is located in the ios
project folder. If you’re working in Xcode, perform the following steps:
- Add a row with the name
Braze
and type ofDictionary
. - To that Dictionary, add a row with the name
Endpoint
, typeString
and as a value, input your SDK endpoint.
Otherwise, add the following elements to the file:
1
2
3
4
5
<key>Braze</key>
<dict>
<key>Endpoint</key>
<string>sdk.your-endpoint.com</string>
</dict>
Step 3: Usage
To import the plugin into your Dart code, use the following:
1
import 'package:braze_plugin/braze_plugin.dart';
Then, initialize an instance of the Braze plugin by calling new BrazePlugin()
like in our sample app.
Test your basic integration
At this point, you can verify that the SDK is integrated by checking session statistics in the dashboard. If you run your application on either platform, you should see a new session in dashboard (in the Overview section).
You can open a session for a particular user by calling the following code in your app.
1
2
BrazePlugin braze = BrazePlugin();
braze.changeUser("some-user-id");
Then, search for the user with some-user-id
in the dashboard under User Search. There, you can verify that session and device data have been logged.