flutter_survey_intercept 0.1.8-beta.1
flutter_survey_intercept: ^0.1.8-beta.1 copied to clipboard
Flutter plugin for QuestionPro CX survey intercept. Enables rule-based in-app surveys on Flutter mobile apps.
flutter_survey_intercept #
A Flutter plugin for QuestionPro CX SDK integration, enabling survey intercept functionality on iOS and Android platforms.
Features #
- Seamless integration with QuestionPro CX SDK
- Survey intercept capabilities for mobile applications
- Cross-platform support (iOS 14.0+ and Android)
- Native bridge implementation for both platforms
Getting started #
Add this to your package's pubspec.yaml file:
dependencies:
flutter_survey_intercept: ^0.1.8
Then run:
flutter pub get
Android Configuration #
1. Add JitPack Repository
In your app's android/settings.gradle, add JitPack to the repositories:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") } // Required for QuestionProCX SDK
}
}
Legacy projects: If your project uses
android/build.gradle(project level) instead ofsettings.gradle, add JitPack there:allprojects { repositories { google() mavenCentral() maven { url = uri("https://jitpack.io") } } }
2. Configure AndroidManifest.xml
Add the following permissions and API key to your android/app/src/main/AndroidManifest.xml if not already added:
<uses-permission android:name="android.permission.INTERNET"/>
Note: Most manifest merger conflicts are already handled by the plugin. If you still encounter issues, add xmlns:tools="http://schemas.android.com/tools" to your <manifest> tag and tools:replace="android:label" to your <application> tag.
iOS Configuration #
The plugin supports two approaches for iOS dependency resolution:
Option A — Swift Package Manager (Flutter 3.22+, Recommended)
SPM is the recommended approach. The plugin's Package.swift automatically resolves QuestionProCXFramework — no Podfile changes needed.
Enable SPM for your Flutter project (one-time setup):
flutter config --enable-swift-package-manager
Then run:
flutter pub get
Flutter will resolve the QuestionProCXFramework dependency automatically when you build.
Important: Your app's iOS deployment target must be set to 14.0 or higher in Xcode — not just in the Podfile. Open
ios/Runner.xcworkspace→ select the Runner target → General → Minimum Deployments → set iOS to14.0.
Option B — CocoaPods
If your project uses CocoaPods, add the QuestionPro CX framework to your ios/Podfile inside your app target:
target 'Runner' do
# ... existing entries
pod 'QuestionProCXFramework', :git => 'https://github.com/surveyanalyticscorp/ios-cx', :tag => '2.3.0'
end
Then run:
cd ios
pod install
cd ..
Note: When a new version of the iOS SDK is released, update the
:tagvalue and runpod update QuestionProCXFramework.
Usage #
Import the package in your Dart code:
import 'package:flutter_survey_intercept/flutter_survey_intercept.dart';
Basic integration #
- Initialize the SDK (for example in your first screen’s
initState):
Future<void> initializeSdk() async {
final result = await FlutterSurveyIntercept.init(
apiKey: 'YOUR_API_KEY',
dataCenter: DataCenter.us,
);
debugPrint('Initialization result: $result');
}
Set the dataCenter value according to your QuestionPro account's data center (for example, DataCenter.eu for EU accounts, DataCenter.us for US accounts). Supported values include DataCenter.us, DataCenter.eu, DataCenter.ca, DataCenter.au, DataCenter.sg, DataCenter.ae, DataCenter.sa, and DataCenter.ksa.
- Track screen visits to drive view-count–based rules:
Future<void> setScreenVisited() async {
try {
final result = await FlutterSurveyIntercept.setScreenVisited(
screenName: 'check_out',
);
debugPrint('Screen view logged successfully: $result');
} catch (e) {
debugPrint('Error logging screen view: $e');
}
}
- Send custom variables via data mappings (used by targeting rules):
Future<void> setDataMappings() async {
try {
final customData = <String, String>{
'firstName': 'first_name',
'lastname': 'last_name',
'email': 'questionpro@example.com',
};
final result = await FlutterSurveyIntercept.setDataMappings(
customVariables: customData,
);
debugPrint('Data mappings set successfully: $result');
} catch (e) {
debugPrint('Error setting data mappings: $e');
}
}
- Register the survey URL listener (typically in
main()beforerunApp):
void main() {
// Start listening for survey URLs from the native SDK
FlutterSurveyIntercept.getSurveyUrlListener();
// Handle survey URL when rules are satisfied
FlutterSurveyIntercept.getSurveyUrl = (url) {
debugPrint('Survey URL received: $url');
// TODO: Open this URL in a WebView or browser
};
}
When the configured rules (view count, data mappings, etc.) are satisfied, the SDK will invoke your FlutterSurveyIntercept.getSurveyUrl callback with the survey URL, which you can present to the user.
Additional information #
This plugin integrates the QuestionPro CX SDK for survey intercept capabilities in Flutter applications.
For issues or questions, please contact the package maintainer.