API reference
Every public type, property and method in the Grovs Flutter plugin 3.1.1.
Grovs() is cheap: every instance talks to the same native SDK. Every method returns a Future that completes once the native SDK has the call, unless noted.
Imports
import 'package:grovs_flutter_plugin/grovs.dart';
import 'package:grovs_flutter_plugin/models/grovs_link.dart';
import 'package:grovs_flutter_plugin/grovs_navigator_observer.dart';| Import | Provides |
|---|---|
grovs.dart | Grovs, every method on this page, and the in-app message types |
models/grovs_link.dart | Parameter and result types |
grovs_navigator_observer.dart | GrovsNavigatorObserver |
At a glance
| Area | Member | Kind | What it does |
|---|---|---|---|
| Setup | Native configuration keys | type | API key and options, set natively |
setSDK | method | Turns collection on or off | |
setDebugLevel | method | Sets the native log level | |
onError | property | Stream of SDK errors (iOS) | |
getPlatformVersion | method | Host OS version | |
| Deep links | onDeeplinkReceived | property | Stream of resolved links and push taps |
handleUrl | method | Resolves a link tapped inside your app | |
| Users | setUserIdentifier | method | Sets your ID for the user |
setUserAttributes | method | Sets user attributes | |
| Links | generateLink | method | Creates a smart link |
linkDetails | method | Gets a link's details by path | |
| Events | track | method | Tracks a custom event |
trackScreenView | method | Tracks a screen view | |
navigatorObserver | property | Automatic screen tracking | |
setGlobalTags | method | Tags added to every event | |
setScreenAliases | method | Renames screens for the dashboard | |
screenAliases | property | Aliases last set | |
| Revenue | logInAppPurchase | method | Logs a store purchase |
logCustomPurchase | method | Logs a purchase outside the store | |
| Push notifications | setPushToken | method | Sets the APNs or FCM token |
isGrovsNotification | method | Checks whether Grovs sent a push | |
handleNotificationOpen | method | Counts a tap and opens the push's link | |
| In-app messages | onInAppMessage | property | Stream of in-app message events |
pauseInAppMessages | method | Holds messages back | |
resumeInAppMessages | method | Lets messages show again | |
discardInAppMessages | method | Drops the waiting message | |
setInAppExcludedScreens | method | Screens where no message shows | |
setInAppDebugLogging | method | Logs why campaigns were skipped | |
| Types | DeeplinkDetails | class | A resolved deep link |
GenerateLinkParams | class | Options for generateLink | |
GrovsLinkDetails | class | Result of linkDetails | |
TrackingParams | class | UTM parameters | |
CustomRedirects | class | Per-platform link redirects | |
CustomLinkRedirect | class | One platform redirect | |
TransactionType | enum | Buy, cancel or refund | |
InAppMessageEvent | sealed class | An event on onInAppMessage | |
InAppDismissReason | enum | Why a message closed | |
GrovsError | class | An SDK error on onError | |
GrovsErrorCode | enum | SDK error categories | |
GrovsException | class | A failed method call | |
| Error codes | type | GrovsException.code values | |
GrovsNavigatorObserver | class | Reports route changes |
Setup
The native SDK is configured before Dart runs, so there's no "not configured" state. See Quick Start.
Native configuration keys
Read once at launch by the native bridges.
| Info.plist | AndroidManifest.xml meta-data | Type | Default |
|---|---|---|---|
GrovsApiKey | grovs_api_key | string | required |
GrovsUseTestEnvironment | grovs_use_test_environment | boolean | false |
GrovsBaseURL | grovs_base_url | string | Grovs cloud |
GrovsClipboardDomains | grovs_clipboard_domains | array of strings on iOS, comma-separated string on Android | none |
GrovsEnabled | grovs_enabled | boolean | true |
setSDK
Future<void> setSDK(bool enabled)Turns collection on or off at runtime, for example when consent changes. See Privacy & Consent.
- While disabled, the native SDK doesn't authenticate, read the clipboard, or send events, screen views or purchases. The plugin drops deep links.
- Enabling replays the link that launched the app while disabled.
- Setting the current state is a no-op.
- Not persisted. Set the initial state with
GrovsEnabled/grovs_enabled.
setDebugLevel
Future<void> setDebugLevel(String level)Sets the native log level: 'info' for everything, 'error' for errors only.
- Case-insensitive. Any other value means
'error'.
onError
Stream<GrovsError> get onErrorBroadcast stream of asynchronous native SDK errors, as GrovsError. See Handling SDK errors.
- iOS only. On Android it never emits.
- iOS buffers the 20 most recent errors before the first listener.
- Unknown error codes are dropped.
- In-app display failures arrive on
onInAppMessageasInAppMessageFailed, not here.
getPlatformVersion
Future<String?> getPlatformVersion()Gets the host OS version, such as "iOS 17.4" or "Android 14". Useful to smoke-test plugin registration.
- The only method that lets the raw
PlatformExceptionthrough instead ofGrovsException.
Deep links
onDeeplinkReceived
Stream<DeeplinkDetails> get onDeeplinkReceivedBroadcast stream of DeeplinkDetails for every resolved link, including deferred links matched after install, links passed to handleUrl and taps on Grovs pushes. See Deep Linking.
- Up to 20 events before the first listener are buffered and replayed to it.
- Nothing is emitted while disabled.
- For a push without a link,
linkisnull. See What your app receives.
handleUrl
Future<bool> handleUrl(String url)Resolves a Grovs link tapped inside your app. The system doesn't hand a universal link or App Link back to the app that opened it. The result arrives on onDeeplinkReceived. See Links tapped inside your app.
Returns true when the link was handed to the native SDK.
urlmust be absolute, with a scheme and a host. Otherwise throwsINVALID_ARGUMENT.- Returns
falsewithout queuing the link while the SDK is disabled, and on Android when no activity is attached.
Users
setUserIdentifier
Future<void> setUserIdentifier(String identifier)Sets your identifier for the current user, typically your user_id. Shown in the dashboard and reports.
- Held while the SDK is disabled.
setUserAttributes
Future<void> setUserAttributes(Map<String, dynamic> attributes)Sets attributes of the current user, shown in the dashboard.
- Values must be platform-channel encodable: null, booleans, numbers, strings, lists, or maps with string keys.
- Held while the SDK is disabled.
Links
generateLink
Future<String> generateLink(GenerateLinkParams params)Creates a smart link. Fields: GenerateLinkParams. See Link Creation.
Returns the URL. Completes when the native operation finishes.
- Throws
GrovsExceptionwithGENERATION_ERRORwhen generation fails, including while disabled or unauthenticated.
linkDetails
Future<GrovsLinkDetails> linkDetails(String path)Gets the details of a link by its path, the last part of the link (abc123 for https://yourapp.sqd.link/abc123). Pass the path only, not the full URL. See Link details.
Returns a GrovsLinkDetails.
- Throws
INVALID_ARGUMENTwhenpathis empty or whitespace,SDK_DISABLEDwhile the SDK is disabled, andLINK_DETAILS_ERRORwhen the link isn't found or the request fails.
Events
track
Future<void> track(
String name, {
Map<String, dynamic>? properties,
List<String>? tags,
})Tracks a custom event.
- The name can't be empty or a reserved system name.
- Rules and limits: Tracking custom events.
trackScreenView
Future<void> trackScreenView(
String screenName, {
Map<String, dynamic>? properties,
})Tracks a screen view manually.
- The native SDK drops a repeat of the same screen within one second.
navigatorObserver
static GrovsNavigatorObserver get navigatorObserverA shared GrovsNavigatorObserver for automatic screen tracking. See Automatic screen tracking.
MaterialApp(
navigatorObservers: [Grovs.navigatorObserver],
)setGlobalTags
Future<void> setGlobalTags(List<String>? tags)Sets tags merged onto every later event. Pass null to clear them.
setScreenAliases
Future<void> setScreenAliases(Map<String, String> aliases)Maps raw screen names to dashboard names. See Screen name aliases.
- Stored in Dart for
GrovsNavigatorObserverand forwarded to the native SDK, which syncs it.
screenAliases
static Map<String, String> get screenAliasesUnmodifiable view of the aliases last passed to setScreenAliases. GrovsNavigatorObserver applies them to automatic screen views.
Revenue
See Revenue.
logInAppPurchase
Future<void> logInAppPurchase(String transactionId)Logs a platform store purchase. Completes when the native operation finishes.
| Platform | Pass |
|---|---|
| iOS | The StoreKit 2 transaction ID as a decimal string. |
| Android | The Play Billing purchase's originalJson. |
- On iOS, a value that isn't an unsigned 64-bit integer throws
INVALID_ARGUMENT. - A purchase the native SDK couldn't log throws
PAYMENT_ERROR.
logCustomPurchase
Future<void> logCustomPurchase({
required TransactionType type,
required int priceInCents,
required String currency,
required String productId,
DateTime? startDate,
})Logs a purchase, cancellation or refund made outside the platform store. Completes when the native operation finishes.
| Name | Type | Description |
|---|---|---|
type | TransactionType | buy, cancel or refund. |
priceInCents | int | Price in cents. |
currency | String | ISO 4217 code. |
productId | String | Your product identifier. |
startDate | DateTime? | Sent as epoch milliseconds and honored on both platforms. Defaults to now. |
Push notifications
setPushToken
Future<void> setPushToken(String token)Sets the push token for push campaigns: the APNs device token on iOS, the FCM registration token on Android. See Push notifications.
- iOS: not needed. The plugin passes the APNs token once the app registers for remote notifications. Calling it still works, with one extra attributes update.
- Android: the plugin fetches the first FCM token when Firebase is present, and again on
setSDK(true). Pass refreshes fromonTokenRefresh. - Held while the SDK is disabled.
isGrovsNotification
Future<bool> isGrovsNotification(Map<String, dynamic> data)Checks whether Grovs sent a push, without handling it. Pass the push's data, for example RemoteMessage.data from firebase_messaging.
Returns true when the data has a non-empty grovs_campaign_id.
handleNotificationOpen
Future<bool> handleNotificationOpen(Map<String, dynamic> data)Counts a tap on a Grovs push and opens its link. The push is delivered on onDeeplinkReceived. See Handling taps yourself.
Returns true when the data belongs to a Grovs push and the tap was handled. false for other pushes and while the SDK is disabled.
- Call it only from a tap handler, never when a push is delivered.
- Only when the native path isn't wired. On iOS, setting the notification center delegate and also calling this counts each tap twice.
- On Android, values in
dataare passed as strings.
In-app messages
See In-app messages.
onInAppMessage
Stream<InAppMessageEvent> get onInAppMessageBroadcast stream of InAppMessageEvent: shown, clicked, dismissed, answered and failed.
- Up to 20 events before the first listener are buffered and replayed to it.
- On Android, events sent while no Flutter engine is attached are dropped. On iOS they're kept for the next engine.
- Nothing is emitted while disabled.
- Events with an unknown type or a missing required field are dropped.
pauseInAppMessages
Future<void> pauseInAppMessages()Holds in-app messages back until resumeInAppMessages. The newest highest priority one waits.
resumeInAppMessages
Future<void> resumeInAppMessages()Lets messages show again after pauseInAppMessages or discardInAppMessages, starting with the one that waited, if it still qualifies.
discardInAppMessages
Future<void> discardInAppMessages({bool dismissCurrent = false})Drops the waiting message and stays paused. Call resumeInAppMessages to show new ones. With dismissCurrent: true, also closes the message on screen.
setInAppExcludedScreens
Future<void> setInAppExcludedScreens(List<String> screens)Sets screens where no message shows. Messages wait until the user leaves.
- Matched against the names sent by
trackScreenViewandGrovsNavigatorObserver, after screen aliases are applied. - Case is ignored.
setInAppDebugLogging
Future<void> setInAppDebugLogging(bool enabled)Logs each campaign considered for an event and why it was skipped.
- On iOS, also call
setDebugLevel('info')to see the logs. - On Android, logs go to Logcat under the tag
GrovsInApp, whatever the debug level.
Types
DeeplinkDetails
class DeeplinkDetails {
final String? link;
final Map<String, dynamic>? data;
final TrackingParams? tracking;
}A resolved deep link, emitted on onDeeplinkReceived.
| Name | Type | Description |
|---|---|---|
link | String? | The link that opened the app, or null if unavailable. |
data | Map<String, dynamic>? | The custom payload attached to the link. |
tracking | TrackingParams? | UTM campaign, source and medium for the link, or null. |
toMap()returns the same fields as a map, withtrackingexpanded to its threeutm_keys.
GenerateLinkParams
class GenerateLinkParams {
GenerateLinkParams({
required String title,
String? subtitle,
String? imageURL,
Map<String, dynamic>? data,
List<String>? tags,
CustomRedirects? customRedirects,
bool? showPreviewIos,
bool? showPreviewAndroid,
bool? copyToClipboardIos,
bool? copyToClipboardAndroid,
TrackingParams? tracking,
});
}Options for generateLink. See Link Creation.
| Name | Type | Description |
|---|---|---|
title | String | Link preview title. Required. |
subtitle | String? | Link preview subtitle. |
imageURL | String? | Link preview image URL. |
data | Map<String, dynamic>? | Custom payload delivered on deep link open. |
tags | List<String>? | Tags for filtering and analytics. |
customRedirects | CustomRedirects? | Per-platform redirect overrides. |
showPreviewIos | bool? | Show the preview page on iOS. null uses the project default. |
showPreviewAndroid | bool? | Show the preview page on Android. null uses the project default. |
copyToClipboardIos | bool? | Copy the link on the iOS preview page, for clipboard-assisted deferred deep linking. null uses the project setting. |
copyToClipboardAndroid | bool? | Same, for Android. |
tracking | TrackingParams? | UTM campaign, source and medium. |
GrovsLinkDetails
class GrovsLinkDetails {
final int? id;
final String? name;
final String? path;
final String? title;
final String? subtitle;
final String? image;
final String? accessPath;
final bool? active;
final bool? sdkGenerated;
final Map<String, dynamic>? data;
final List<String>? tags;
final DateTime? updatedAt;
final bool? showPreviewIos;
final bool? showPreviewAndroid;
final String? generatedFromPlatform;
final String? adsPlatform;
final int? campaignId;
final TrackingParams? tracking;
final CustomRedirects? customRedirects;
final Map<String, dynamic> raw;
}The result of linkDetails.
| Name | Description |
|---|---|
path | The last part of the link, for example abc123. |
image | URL of the link's preview image. |
accessPath | The full link URL. |
data | The payload attached to the link, as received. |
tracking | UTM campaign, source and medium, or null when none is set. |
customRedirects | Per-platform redirects, or null when none is set. A redirect without open_app_if_installed gets openAppIfInstalled: true. |
raw | Every field the backend sent, as received. Numbers can be doubles on Android and ints on iOS. |
- A field whose value has an unexpected type is
null. Typed fields are the same on both platforms.
TrackingParams
class TrackingParams {
TrackingParams({String? utmCampaign, String? utmSource, String? utmMedium});
}UTM parameters for link generation, and a received link's tracking metadata.
CustomRedirects
class CustomRedirects {
CustomRedirects({
CustomLinkRedirect? ios,
CustomLinkRedirect? android,
CustomLinkRedirect? desktop,
});
}Per-platform redirect overrides for generateLink.
CustomLinkRedirect
class CustomLinkRedirect {
CustomLinkRedirect({required String url, bool openAppIfInstalled = true});
}One platform redirect. When openAppIfInstalled is true, the app opens if installed. Otherwise url is always used.
TransactionType
enum TransactionType { buy, cancel, refund }Used with logCustomPurchase.
InAppMessageEvent
sealed class InAppMessageEvent {
String? get campaignId;
}
final class InAppMessageShown extends InAppMessageEvent {
final String campaignId;
}
final class InAppMessageClicked extends InAppMessageEvent {
final String campaignId;
final String? buttonId;
final Map<String, dynamic>? payload;
}
final class InAppMessageDismissed extends InAppMessageEvent {
final String campaignId;
final InAppDismissReason reason;
}
final class InAppMessageAnswered extends InAppMessageEvent {
final String campaignId;
final Object value;
final String? comment;
}
final class InAppMessageFailed extends InAppMessageEvent {
final String? campaignId;
final String message;
}An event on onInAppMessage. Exported from grovs.dart. See React to messages.
| Class | Sent when |
|---|---|
InAppMessageShown | The message is on screen and counted as viewed. |
InAppMessageClicked | A button or the message was tapped. buttonId is null for the message. payload carries a key-value action's pairs. |
InAppMessageDismissed | The message closed without a click. |
InAppMessageAnswered | A question was answered and the message closed, in place of the dismissal. value is the star rating (int) or the chosen option's ID. |
InAppMessageFailed | The message couldn't be drawn. campaignId is null on iOS. |
InAppDismissReason
enum InAppDismissReason { closeButton, backdrop, swipe, app, orientation, unknown }Why a message closed, on InAppMessageDismissed.
| Value | Native value | Meaning |
|---|---|---|
closeButton | close_button | The close button. |
backdrop | backdrop | A tap outside the message. |
swipe | swipe | Swiped away. |
app | app | Closed by the SDK or your app. |
orientation | orientation | The device turned to an orientation the campaign doesn't allow. |
unknown | anything else | A value this plugin version doesn't know. |
GrovsError
class GrovsError {
final GrovsErrorCode code;
final String message;
}An SDK error, emitted on onError.
GrovsErrorCode
enum GrovsErrorCode {
authenticationFailed, // 'authentication_failed'
networkRequestFailed, // 'network_request_failed'
eventDispatchFailed, // 'event_dispatch_failed'
linkGenerationFailed, // 'link_generation_failed'
}The category of a GrovsError.
nativeNameis the native snake-case name.GrovsErrorCode.fromNativeNamemaps a name back to a value, ornullif unknown.
GrovsException
class GrovsException implements Exception {
final String message;
final String? code;
}Thrown when a native call fails. Every method except getPlatformVersion uses it.
codeis one of the error codes, ornullfor a Dart-side failure.
Error codes
GrovsException.code values raised by the native bridges:
| Code | Platform | Raised when |
|---|---|---|
INVALID_ARGUMENT | both | A required argument is missing, TransactionType is unknown, the handleUrl URL has no scheme or host, the linkDetails path is empty (checked in Dart), or on iOS the logInAppPurchase transaction ID is not an unsigned 64-bit integer. |
GENERATION_ERROR | both | generateLink failed. |
SDK_DISABLED | both | linkDetails was called while the SDK is disabled. |
LINK_DETAILS_ERROR | both | linkDetails found no link or the request failed. |
PAYMENT_ERROR | both | logInAppPurchase or logCustomPurchase failed: the native completion reported failure on iOS, or the native call threw on Android. |
TOKEN_ERROR | Android | setPushToken threw natively. |
USER_ERROR | Android | setUserIdentifier or setUserAttributes threw natively. |
DEBUG_ERROR | Android | setDebugLevel threw natively. |
EVENT_ERROR | Android | An event method (track, trackScreenView, setGlobalTags or setScreenAliases) threw natively. |
CONSENT_ERROR | Android | setSDK threw natively. |
- On iOS the user, event and consent setters are fire-and-forget and never throw.
GrovsNavigatorObserver
class GrovsNavigatorObserver extends NavigatorObserver {
GrovsNavigatorObserver({
String? Function(Route<dynamic> route)? screenNameExtractor,
Grovs? grovs,
});
}Reports a screen view for each route change. Use the shared Grovs.navigatorObserver, or construct one to customize names. See Automatic screen tracking.
| Navigator event | Route reported |
|---|---|
didPush | The pushed route |
didReplace | The new route |
didPop | The route revealed |
- Only
PageRoutes are reported. - The name comes from
screenNameExtractor, thenRouteSettings.name, then the runtime type. It's translated throughGrovs.screenAliases.