Guides and Surveys Flutter SDK
Alpha
This feature is experimental. Expect this feature to change as development continues. Because the feature continues to evolve, this documentation may be out of date.
Amplitude's Guides and Surveys Flutter SDK lets you deploy Guides and Surveys in your Flutter applications.
Requirements
The Guides and Surveys Flutter SDK requires:
- Dart 3.3+
- Flutter 3.7+
- Amplitude Analytics Flutter SDK 4.4.0+
Installation
Install the SDK
Add the Guides and Surveys package and the Amplitude Analytics SDK to your pubspec.yaml:
dependencies:
amplitude_flutter: ^4.4.0
amplitude_engagement_flutter: ^0.0.5
Run flutter pub get to install the dependencies.
Run pod install in the ios directory.
cd ios
pod install
Initialize the SDK
import 'package:app_links/app_links.dart';
import 'package:amplitude_flutter/amplitude.dart';
import 'package:amplitude_flutter/configuration.dart';
import 'package:amplitude_engagement_flutter/amplitude_engagement.dart' as engagement;
// Initialize Analytics
final amplitude = Amplitude(Configuration(apiKey: 'YOUR_API_KEY'));
// Connect the engagement SDK to the analytics instance
await engagement.installAmplitudeEngagementPlugin(amplitude);
// Handle deep links for preview mode
final appLinks = AppLinks();
appLinks.getInitialLink().then((uri) async {
if (uri != null) {
final didHandleURL = await engagement.handleURL(uri.toString());
if (didHandleURL) { return; }
// Handle a non-Amplitude SDK URL
}
});
appLinks.uriLinkStream.listen((uri) async {
final didHandleURL = await engagement.handleURL(uri.toString());
if (didHandleURL) { return; }
// Handle a non-Amplitude SDK URL
});
installAmplitudeEngagementPlugin initializes the engagement SDK using the same API key and passes the native analytics instance to the engagement layer on iOS and Android.
Configuration options
Pass an AmplitudeInitOptions object to installAmplitudeEngagementPlugin to configure the SDK:
await engagement.installAmplitudeEngagementPlugin(amplitude, options: AmplitudeInitOptions(
serverZone: AmplitudeServerZone.eu,
logLevel: AmplitudeLogLevel.debug,
));
| Parameter | Type | Description |
|---|---|---|
serverZone | EU or US | Optional. Sets the Amplitude server zone. Set this to EU for Amplitude projects created in the EU data center. Default: US |
serverUrl | string | Optional. Custom server URL for API requests. Useful for proxy setups. |
cdnUrl | string | Optional. Custom CDN URL for static assets. Useful for proxy setups. |
mediaUrl | string | Optional. Custom URL for proxying nudge images. Useful for proxy setups when firewalls block images. |
logLevel | LogLevel enum | Optional. Sets the log level. Default: LogLevel.warn |
locale | string | Optional. Sets the locale for localization. Defaults to the device's system language (for example, en). Note that the default is a language code only, not a full locale identifier like en-US. |
Use the same API key for Guides & Surveys and Analytics
To avoid analytics mismatches and ensure accurate data collection, use the same API key for both Guides & Surveys and your Analytics SDK. Both should reference the same Amplitude project. Using different API keys can cause:
- The SDK to fetch guides and surveys from the wrong project.
- Analytics data to appear in different projects.
- Insights and survey responses are incomplete or mismatched.
Make sure the API key you provide to Guides & Surveys matches the API key used to initialize your Amplitude Analytics SDK.
Boot the SDK
Boot the SDK with a user ID to enable Guides and Surveys:
import 'package:amplitude_flutter/amplitude.dart';
import 'package:amplitude_flutter/events/identify.dart';
import 'package:amplitude_engagement_flutter/amplitude_engagement.dart' as engagement;
// Setting the User ID in Amplitude Analytics
// --and-- passing it to boot() is necessary
amplitude.setUserId('test-user-1');
// boot(userId, deviceId, userProperties)
await engagement.boot(
userId: 'test-user-1',
deviceId: 'test-device-1', // optional if userId is set
userProperties: {'plan': 'premium'}, // optional
);
At this point, you're technically done installing. While optional, Amplitude recommends that you set up URL handling for preview mode.
Add your application to project settings
After installing the SDK, add your Flutter application to your Amplitude project settings so it appears as a platform option when you create guides and surveys.
To add your application:
- Navigate to Settings > Projects in Amplitude.
- Select your project.
- Navigate to the Guides and Surveys tab.
- In the App Management section, expand and click + Add App.
- Select Flutter from the dropdown.
After you add your application, it appears as a platform option when you create or edit guides and surveys. This enables you to deliver guides and surveys to your Flutter app users.
Set a minimum SDK version (when needed)
Minimum SDK version is available for mobile SDK versions 3.0.0 and later. Use this setting as a safety control when you identify a critical issue in an older SDK release.
To configure a minimum SDK version:
- Navigate to Settings > Projects in Amplitude.
- Select your project.
- Navigate to the Guides and Surveys tab.
- In the App Management section, expand and click + Add App.
- Select Flutter from the dropdown.
- Enter a value in Minimum SDK version.
When you set this value, Guides and Surveys compares the configured minimum with the SDK version in each app build:
- If an app build uses an older SDK version, the SDK doesn't initialize in that build.
- If an app build uses the same or newer SDK version, the SDK initializes as expected.
This setting lets you stop guides and surveys on known problematic SDK versions without rolling back your application release.
Screen tracking
Call screen to enable screen-based targeting and the Time on Screen trigger. Guides and Surveys compares the screen string (for example, "HomeScreen") with the string you set in the guide or survey page targeting section.
engagement.screen('HomeScreen');
Element targeting
Pin and tooltip guides require the SDK to target specific widgets on screen. The SDK automatically enables element targeting on initialization.
Tag targetable widgets with AmplitudeEngagementView as a SemanticsTag to give them a stable identifier. In the example below, use "welcome-banner" as the element targeting string in the Guides and Surveys dashboard.
import 'package:flutter/material.dart';
import 'package:amplitude_engagement_flutter/amplitude_engagement.dart' as engagement;
Semantics(
tagForChildren: const engagement.AmplitudeEngagementView('welcome-banner'),
child: Banner(
child: Text('Welcome to the app'),
),
)
Simulate Guides and Surveys for preview
Previewing guides and surveys directly in your application lets you experience what your users see. Previewing makes it easier to iterate on copy, targeting rules, and trigger logic.
Deep linking required for preview
If your app doesn't have deep linking enabled, follow Flutter's instructions to add support for deep linking. Previewing guides and surveys on a phone, tablet, or simulator requires this configuration.
Set up preview in Xcode (iOS)
Locate the mobile URL scheme
To locate the URL scheme:
- Navigate to Settings > Projects in Amplitude.
- Select your project.
- Navigate to the General tab.
- Find the URL scheme (mobile) field.
- Copy its value, for example,
amp-abcdefgh12345678.
Add the URL scheme in Xcode
- Open your iOS project in Xcode.
- In the Project navigator, select your app's target.
- On the Info tab, locate or add the URL Types section.
- Add a new URL type with the following values:
- URL identifier: Provide a descriptive name, like
AmplitudeURLSchemefor example. - URL Schemes: Paste the value you copied from Amplitude, for example
amp-abc123.
- URL identifier: Provide a descriptive name, like
Set up preview in Android Studio (Android)
Locate the mobile URL scheme
To locate the URL scheme:
- Navigate to Settings > Projects in Amplitude.
- Select your project.
- Navigate to the General tab.
- Find the URL scheme (mobile) field.
- Copy its value, for example,
amp-abcdefgh12345678.
Add the URL scheme in Android Studio
Add the following intent filter to the main activity in your project's AndroidManifest.xml file:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Add your URL scheme from Amplitude Dashboard here -->
<!-- ex: android:scheme="amp-12345" -->
<data android:scheme="<your-unique-scheme-id>" />
</intent-filter>
</activity>
URL handling for preview links
The initialization code snippet already takes care of URL handling for preview links. Specifically, this code:
final appLinks = AppLinks();
appLinks.getInitialLink().then((uri) async {
if (uri != null) {
final didHandleURL = await engagement.handleURL(uri.toString());
if (didHandleURL) { return; }
// Handle a non-Amplitude SDK URL
}
});
appLinks.uriLinkStream.listen((uri) async {
final didHandleURL = await engagement.handleURL(uri.toString());
if (didHandleURL) { return; }
// Handle a non-Amplitude SDK URL
});
Super Debugger
When you scan a preview QR code from the Amplitude dashboard, a small blue Amplitude logo appears at the bottom of your screen. Tap it to open the Super Debugger panel.
The Super Debugger has two tabs: Details and Setup.
Details tab
The Details tab shows information about the guide or survey you're previewing and lets you inspect and control the preview session.
Guide / Survey: The name of the active guide or survey. Tap it to switch to a different guide or survey.
Details:
- Step: The current step number out of the total (for example, "1 of 3"). Tap the copy icon to copy the value.
- User: The user ID for the preview session. Tap the copy icon to copy it.
- Screen: The screen name the SDK currently reports. Tap the copy icon to copy it.
Debug: Shows whether the guide or survey passes each condition check. Each row expands to show details:
- Limits: Whether the guide or survey has reached its display limit. Expand to see the configured limit.
- Trigger: Whether the guide or survey meets the trigger condition. Expand to see the trigger type, screen conditions, and pin target element (if applicable).
- Throttle: Whether the guide or survey meets the throttle condition. Expand to see the throttle setting. Toggle Ignore limits to bypass throttle limits during your preview session.
Advanced:
- Pin Debugging: Expand to enable Reposition pins every 5 seconds. This periodically re-evaluates pin positions, which is useful for debugging pin placement on dynamic layouts.
At the bottom of the panel:
- Restart Preview: Resets the guide or survey to its first step and restarts the preview.
- Close Preview: Exits preview mode and dismisses the Super Debugger.
Setup tab
The Setup tab shows SDK configuration and environment details for the current session.
SDK Versions: The version of the Engagement SDK installed in your app.
Installation:
- Type: The SDK installation method (for example, Plugin or standalone).
- Configuration: The number and type of custom configuration options applied.
User:
- User ID: The user ID passed to the SDK on boot.
- Properties: Any user properties set for the current session.
Event Flow: Confirms whether events are flowing correctly:
- Events flowing into Guides and Surveys SDK: Events from your analytics instance reach the Engagement SDK.
- Events flowing out of Guides and Surveys SDK: The Engagement SDK sends events to Amplitude.
Support
Tap the ? button to open the Support panel. From here you can:
- Open links to the SDK documentation and Guides and Surveys overview.
- File Bug Report: Submit a bug report directly from the debugger. Fill in steps to reproduce, expected results, and actual results, then tap Send.
Other SDK methods
Manage themes
engagement.setThemeMode(AmplitudeThemeMode.dark); // Options: auto, light, dark
Register a callback
engagement.addCallback('show-alert', () {
// Custom logic when the guide or survey triggers this callback
});
Reset
engagement.reset('GUIDE_KEY', 0);
List
final guidesAndSurveys = await engagement.list();
Show
engagement.show('GUIDE_KEY');
Forward event
Use forwardEvent to enable the On event tracked trigger in Guides and Surveys. The SDK doesn't send forwarded events to Amplitude servers; it uses them only for local trigger evaluation.
engagement.forwardEvent({
'event_type': 'Button Clicked',
'event_properties': {'name': 'Submit'},
});
Close all
engagement.closeAll();
Localization
The SDK defaults to the device's system language when you don't set the locale option at initialization. The default is a language code only (for example, en), not a full locale identifier like en-US.
To set a specific language, pass the locale option when you initialize the SDK:
import 'package:amplitude_flutter/amplitude.dart';
import 'package:amplitude_engagement_flutter/amplitude_engagement.dart' as engagement;
final amplitude = Amplitude(Configuration(apiKey: 'YOUR_API_KEY'));
await engagement.installAmplitudeEngagementPlugin(amplitude, options: AmplitudeInitOptions(
locale: 'es-ES',
));
Known limitations
Targeting animated elements and elements inside moving containers
Pins and tooltips can't target widgets that are:
- Animated or inside an animated container (they move on screen).
- Inside a container that moves based on user interaction.
Scrollable views usually work.
Workaround
Use screen-based targeting or event-based triggers to show guides, perhaps with a delay to ensure any animations have completed. Don't pin directly to elements in animated containers or containers that users can move through interaction.
Changelog
You can access the changelog here.
Was this helpful?