Flutter SDK Integration Guide
Your dedicated account representative will help configure your account for the platforms that you are targeting with your Flutter App. They will provide you with both the key (iOS/Android/Web) and secret (iOS/Android) required to initialize the SDK and additional resources needed to render the most relevant experiences for your customers.
These instructions require development resources to complete. If you require additional assistance, please reach out to your Rokt account manager. Shopify stores can set up a Rokt placement in seconds using the Rokt Ecommerce app — no coding needed!
1. Flutter setup
Add the Flutter SDK as a dependency to your Flutter application:
flutter pub add mparticle_flutter_sdk
After adding the Rokt Flutter SDK dependency to your application, the following (or similar) lines are added to your package’s pubspec.yaml file:
dependencies:
mparticle_flutter_sdk: ^1.1.0
Import the package into your Dart code and get an instance of mParticle:
import 'package:mparticle_flutter_sdk/mparticle_flutter_sdk.dart';
MparticleFlutterSdk? mpInstance = await MparticleFlutterSdk.getInstance();
After installing the Dart plugin, continue integrating the Rokt SDK into your mobile app or website by following the steps below. Be sure to include the key and secret provided by your account manager where required or you will see errors in your logs when launching your app or site.
1.1. Add the Rokt SDK to your iOS app
Using either SPM or CocoaPods, include the Rokt SDK in your application:
CocoaPods
To integrate the SDK using CocoaPods, specify it in your Podfile with:
pod 'mParticle-Apple-SDK', '~> 8.0'
pod 'mParticle-Rokt','~> 8.0'
SPM
To integrate the SDK using Swift Package Manager:
- Open your project in Xcode, and go to the "Package Dependencies" tab.
- Click the + button under the Packages list.
- Enter the repository URL
https://github.com/mParticle/mparticle-apple-sdk
in the search box on the top right, choosemparticle-apple-sdk
from the list of packages, and change "Dependency Rule" to "Up to Next Major Version". - Click the "Add Package" button on the bottom right, and choose either the "Package Product" called
mParticle-Apple-SDK
. If you'd like to use a version of the SDK that doesn't include location tracking support, choosemParticle-Apple-SDK-NoLocation
. - Repeat steps 3 & 4 for the Rokt Kit repository URL
https://github.com/mparticle-integrations/mparticle-apple-integration-rokt.git
.- If you choose the
mParticle-Apple-SDK-NoLocation
package product, you will need to import the SDK usingimport mParticle_Apple_SDK_NoLocation
instead ofimport mParticle_Apple_SDK
.
- If you choose the
1.2. Initialize the Rokt SDK
To initialize the SDK, insert the following initialization snippet in your AppDelegate file:
- Make sure to replace
your-key
andyour-secret
with the key and secret provided by your dedicated Rokt team.
- Swift
- Objective-C
import mParticle_Apple_SDK
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Initialize the SDK
let options = MParticleOptions(key: "your-key",
secret: "your-secret")
// Specify the data environment with environment:
// Set it to .development if you are still testing your integration.
// Set it to .production if your integration is ready for production data.
// The default is .autoDetect which attempts to detect the environment automatically
options.environment = .development
MParticle.sharedInstance().start(with: options)
return true
}
#import <mParticle_Apple_SDK/mParticle.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Initialize the SDK
MParticleOptions *options = [MParticleOptions optionsWithKey:@"your-key"
secret:@"your-secret"];
// Specify the data environment with environment:
// Set it to MPEnvironmentDevelopment if you are still testing your integration.
// Set it to MPEnvironmentProduction if your integration is ready for production data.
// The default is MPEnvironmentAutoDetect which attempts to detect the environment automatically
options.environment = MPEnvironmentDevelopment;
[[MParticle sharedInstance] startWithOptions:options];
return YES;
}
Further setup
For further help, see the full iOS SDK Integration Guide.
1.1 Add dependencies
Update your gradle file to include the necessary dependencies for the SDK:
- build.gradle.kts
- build.gradle
dependencies {
implementation("com.mparticle:android-rokt-kit:5.70.2")
implementation("com.mparticle:android-core:5.70.2")
}
dependencies {
implementation "com.mparticle:android-rokt-kit:5.70.2"
implementation "com.mparticle:android-core:5.70.2"
}
1.2. Configure your Android classes
Ensure your root Android Activity extends FlutterFragmentActivity
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity : FlutterFragmentActivity()
1.3. Initialize the SDK in your app
The Android SDK can be configured using an MParticleOptions
object and a builder class in the onCreate()
of the Application
class. The mParticle Android SDK should be initialized before any other SDK API calls are made.