SDK API reference
The SDK API provides the following methods with their signatures, parameters, and usage examples.
GDPR / Identification
Section titled GDPR / IdentificationCSQ().optIn()
Section titled CSQ().optIn()1.0.0
Get user consent. Calling this API generates a user ID and initiates tracking.
await CSQ().optIn();Parameters
Section titled ParametersNo parameters.
CSQ().optOut()
Section titled CSQ().optOut()1.0.0
Revoke user consent, remove stored userID.
Stop CSQ SDK, flush, and clear all data.
await CSQ().optOut();Parameters
Section titled ParametersNo parameters.
CSQ().identify()
Section titled CSQ().identify()Product Analytics | Added in: 1.0.0
Assigns an identity to be associated with the current user.
This assigns the identity to all events for the user ID and lets the analysis module merge multiple user IDs with the same identity.
This should be called only after Product Analytics is configured and the SDK started. It's safe to call multiple times with the same value. Always provide a value that will be unique to this user. Setting values like "guest", "anonymous", "unauthenticated" or similar will merge all those users into a single user profile.
await CSQ().identify(userIdentifier: 'userIdentity');Parameters
Section titled Parameters-
userIdentifier String (<= 100 chars)
Identity to be associated with the current user.
CSQ().resetIdentity()
Section titled CSQ().resetIdentity()1.0.0
If the user was previously identified with identify(), this creates a new unidentified user and session. This is technically similar to calling optOut() then optIn().
This should be called only after Product Analytics is configured and the SDK started.
await CSQ().resetIdentity();Parameters
Section titled ParametersNo parameters.
CSQ().metadata
Section titled CSQ().metadata1.0.0
Get all the information related to the user and project.
CSQ().metadata.userId
Section titled CSQ().metadata.userIdIdentifier of the current user.
final userId = CSQ().metadata.userId;CSQ().metadata.sessionId
Section titled CSQ().metadata.sessionIdSession identifier. This is an identifier from Experience Analytics by default or Product Analytics if Experience Analytics is not active.
final sessionId = CSQ().metadata.sessionId;CSQ().metadata.projectId
Section titled CSQ().metadata.projectIdProject identifier for Experience Analytics.
final projectId = CSQ().metadata.projectId;CSQ().metadata.environmentId
Section titled CSQ().metadata.environmentIdEnvironment identifier for Product Analytics.
final environmentId = CSQ().metadata.environmentId;CSQ().metadata.sessionReplayUrl
Section titled CSQ().metadata.sessionReplayUrlURL of current Session Replay.
final sessionReplayUrl = CSQ().metadata.sessionReplayUrl;CSQ().metadata.identity
Section titled CSQ().metadata.identityIdentity associated with the user by calling identify().
final identity = CSQ().metadata.identity;CSQ().metadata.onChange()
Section titled CSQ().metadata.onChange()1.0.0
Listen for changes to user metadata. For example when sessionReplayUrl becomes available or userId updates.
final subscription = CSQ().metadata.onChange((metadata) { // Handle information change});
// Cancel when no longer neededsubscription.cancel();Parameters
Section titled Parameters-
handler void Function(Metadata metadata)
Callback triggered whenever metadata changes. Called immediately with current metadata if available.
Logging
Section titled LoggingCSQ().debug.setLogLevel()
Section titled CSQ().debug.setLogLevel()1.0.0
Sets the current log level.
await CSQ().debug.setLogLevel(LogLevel.debug);Parameters
Section titled Parameters-
logLevel Enum (LogLevel)
Possible values:
all,trace,debug,info,warning,error,important, ornone.
Property Tracking
Section titled Property TrackingCSQ().addDynamicVar()
Section titled CSQ().addDynamicVar()Experience Analytics | Added in: 1.0.0
Adds dynamic variables to the session properties.
This method allows you to pass DynamicVar objects, representing key-value pairs that are scoped to the session.
final var1 = DynamicVar.fromString(key: 'key1', value: 'value1');final var2 = DynamicVar.fromInt(key: 'key2', value: 2);
await CSQ().addDynamicVar(var1);await CSQ().addDynamicVar(var2);Parameters
Section titled Parameters-
dynamicVar DynamicVar
The dynamic variable
key String (<= 50 chars)
Dynamic variable key
value int or String
Dynamic variable value. Use
DynamicVar.fromIntfor integer values (0 to 2³² - 1) orDynamicVar.fromStringfor string values (<= 255 chars).
CSQ().addUserProperties()
Section titled CSQ().addUserProperties()Product Analytics | Added in: 1.0.0
Add a collection of properties to be associated with the current user.
await CSQ().addUserProperties(properties: {'propertyKey': 'propertyValue'});Parameters
Section titled Parameters-
properties Map<String, dynamic>
A map of user properties. Supported value types:
String,num,bool. All other types will be ignored.
CSQ().addEventProperties()
Section titled CSQ().addEventProperties()Product Analytics | Added in: 1.0.0
Add a collection of properties to be associated with all future events.
await CSQ().addEventProperties(properties: {'propertyKey': 'propertyValue'});Parameters
Section titled Parameters-
properties Map<String, dynamic>
A map of event properties. Supported value types:
String,num,bool. All other types will be ignored.
CSQ().removeEventProperty()
Section titled CSQ().removeEventProperty()Product Analytics | Added in: 1.0.0
Removes a single property from the collection of event-wide properties.
await CSQ().removeEventProperty(name: 'propertyKey');Parameters
Section titled Parameters-
name String
The key of the property to remove.
CSQ().clearEventProperties()
Section titled CSQ().clearEventProperties()Product Analytics | Added in: 1.0.0
Removes all event-wide properties.
await CSQ().clearEventProperties();Interoperability
Section titled InteroperabilityCSQWebViewWrapper
Section titled CSQWebViewWrapperExperience Analytics | Added in: 1.0.0
Widget that enables CSQ tracking inside a WebView. Wrap your WebView widget with CSQWebViewWrapper and pass a delegate that supplies the WebView.
To enable WebView support, you must also implement the CSQ WebView JavaScript Tracking Tag in the web pages loaded by the WebView.
Two delegate types are available depending on your WebView package:
UserScriptWebViewWrapperDelegate— for packages likeflutter_inappwebviewthat support user scriptsJSChannelWebViewWrapperDelegate— for packages likewebview_flutterthat use JavaScript channels
// Using UserScriptWebViewWrapperDelegate (for example flutter_inappwebview)CSQWebViewWrapper( delegate: UserScriptWebViewWrapperDelegate( builder: (context, userScript) { return InAppWebView( initialUserScripts: UnmodifiableListView([ UserScript( source: userScript, injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START, ), ]), ); }, ),)
// Using JSChannelWebViewWrapperDelegate (for example webview_flutter)CSQWebViewWrapper( delegate: JSChannelWebViewWrapperDelegate( addJavaScriptChannel: (handler) { webViewController.addJavaScriptChannel( handler.channelName, onMessageReceived: (jsMessage) { handler.onMessageReceived(jsMessage.message); }, ); }, builder: (context) => WebViewWidget(controller: webViewController), ),)Parameters
Section titled Parameters-
delegate WebViewWrapperDelegate
The delegate that supplies the WebView widget to be wrapped.
Event Tracking
Section titled Event TrackingCSQ().trackTransaction()
Section titled CSQ().trackTransaction()Experience Analytics | Added in: 1.0.0
Send a transaction.
final transaction = Transaction( price: 100.0, currency: Currency.USD, id: 'transactionId',);await CSQ().trackTransaction(transaction);Parameters
Section titled Parameters-
transaction Transaction
The transaction object to be sent.
price double
The total transaction amount.
currency Currency
ISO 4217 currency enum value. For example:
Currency.USD,Currency.EUR,Currency.GBP.
id String (optional)
Optional transaction identifier.
CSQ().trackScreenview()
Section titled CSQ().trackScreenview()1.0.0
Send a screen view with or without custom variables. Requires Experience Analytics to be started.
await CSQ().trackScreenview( screenName: 'ScreenName', customVars: [CustomVar(index: 1, name: 'name', value: 'value')],);Parameters
Section titled Parameters-
screenName String
The name of the screen.
-
customVars List<CustomVar> (optional)
A list of custom variables to attach to the screen view.
index int
Custom variable index
name String (<= 512 chars)
Custom variable name
value String (<= 256 chars)
Custom variable value
CSQ().trackEvent()
Section titled CSQ().trackEvent()Product Analytics | Added in: 1.0.0
Creates an event message to be tracked and sent to the API.
await CSQ().trackEvent( eventName: 'EventName', properties: {'propertyKey': 'propertyValue'},);Parameters
Section titled Parameters-
eventName String
The name of the event to be tracked.
-
properties Map<String, dynamic> (optional)
Optional properties to associate with the event. Supported value types:
String,num,bool. All other types will be ignored.
Error tracking
Section titled Error trackingCSQ().setURLMaskingPatterns()
Section titled CSQ().setURLMaskingPatterns()Experience Analytics | Added in: 1.0.0
Sets URL masking patterns.
await CSQ().setURLMaskingPatterns(patterns: ['pattern1', 'pattern2']);Parameters
Section titled Parameters-
patterns List<String>
A list of URL patterns to mask.
CSQ().collectFlutterError()
Section titled CSQ().collectFlutterError()Experience Analytics | Added in: 1.0.0
Sends a report of an error caught by the Flutter framework.
Typically used by assigning it to FlutterError.onError:
FlutterError.onError = (details) { CSQ().collectFlutterError(details: details);};Parameters
Section titled Parameters-
details FlutterErrorDetails
The Flutter error information.
-
presentErrorDetails bool (optional)
Whether to print the error details in the console. Defaults to
true.
CSQ().collectError()
Section titled CSQ().collectError()Experience Analytics | Added in: 1.0.0
Sends a report of a caught error.
Typically used inside a runZonedGuarded error handler:
runZonedGuarded(() { // your app code}, (error, stackTrace) { CSQ().collectError(error: error, stackTrace: stackTrace);});Parameters
Section titled Parameters-
error Object
The error object that was caught.
-
stackTrace StackTrace
The associated stack trace.
CSQ().sendUserIdentifier()
Section titled CSQ().sendUserIdentifier()Experience Analytics | Added in: 1.0.0
Associate a user identifier with the session. This identifier is immediately hashed so no Personal Data can ever be accessed.
await CSQ().sendUserIdentifier(userIdentifier: 'any_identifier');Parameters
Section titled Parameters-
userIdentifier String
The user identifier to track. Should be max 100 characters long.
Personal Data/Masking
Section titled Personal Data/MaskingCSQMask
Section titled CSQMask1.0.0
Applies masking rules to its descendants. Use this widget to mask sensitive content such as personal information, passwords, or any data you don't want collected.
CSQMask( config: const CSQMaskingConfig( maskTexts: true, maskImages: true, maskTextFields: true, maskInteractions: true, ), child: const Text('Sensitive content'),)Parameters
Section titled Parameters-
config CSQMaskingConfig
The masking configuration.
maskTexts bool (optional)
Mask widgets that render text (for example
Text,RichText).maskTextFields bool (optional)
Mask text input widgets (for example
TextField,TextFormField).maskImages bool (optional)
Mask image widgets (for example
Image).maskSvgImages bool (optional)
Mask SVG images.
maskCharts bool (optional)
Mask
fl_chartwidgets.maskCustomPaints bool (optional)
Mask
CustomPaintwidgets.maskInteractions bool (optional)
Prevent user interactions from being captured.
-
child Widget
The widget whose descendants will be masked.
SDK Initialization and Management
Section titled SDK Initialization and ManagementCSQ().start()
Section titled CSQ().start()1.0.0
Start the SDK. Should be called as early as possible in the app's lifecycle.
// Start DXA only (default)await CSQ().start();
// Start PA or PA + DXA with environment ID (Standalone)await CSQ().start( startConfig: StartConfig.withEnvironmentId( id: 'YOUR_ENVIRONMENT_ID', options: AnalyticsOptions(), ),);
// Start PA or PA + DXA with data source ID (Unified CSQ)await CSQ().start( startConfig: StartConfig.withDatasourceId( id: 'YOUR_DATASOURCE_ID', options: AnalyticsOptions(), ),);Parameters
Section titled Parameters-
startConfig StartConfig (optional)
Analytics configuration. Defaults to
StartConfig.dxa(). UseStartConfig.withEnvironmentId()to start Product Analytics (Standalone) orStartConfig.withDatasourceId()for Unified CSQ. -
startConfig.id String
Your Product Analytics environment ID (Standalone) or data source ID (Unified CSQ).
-
startConfig.options AnalyticsOptions
Product Analytics initialization options.
-
maskingConfig CSQMaskingConfig (optional)
Masking configuration for the SDK. See privacy and sensitive data.
CSQ().configureProductAnalytics()
Section titled CSQ().configureProductAnalytics()1.0.0
Configure Product Analytics before calling CSQ().start().
await CSQ().configureProductAnalytics( environmentId: 'YOUR_ENVIRONMENT_ID', options: const ProductAnalyticsOptions( enableInteractionsAutocapture: true, ),);await CSQ().start();Parameters
Section titled Parameters-
environmentId String
Your Product Analytics environment ID.
-
options ProductAnalyticsOptions (optional)
Legacy Product Analytics options. Prefer
AnalyticsOptionsthroughstartConfigwhen migrating toCSQ().start(...).
CSQ().stop()
Section titled CSQ().stop()1.0.0
Stop all activity from the SDK. Once run no requests, telemetry collection, or logs will be generated.
await CSQ().stop();CSQ().pauseTracking()
Section titled CSQ().pauseTracking()1.0.0
Pause all tracking features.
await CSQ().pauseTracking();CSQ().resumeTracking()
Section titled CSQ().resumeTracking()1.0.0
Resume all tracking features.
await CSQ().resumeTracking();Parameters
Section titled ParametersNo parameters.
Session Replay controls
Section titled Session Replay controlsCSQ().startSessionReplay()
Section titled CSQ().startSessionReplay()Experience Analytics | Added in: 4.2.0
Starts Session Replay on-demand.
Use this API when Session Replay automatic start is disabled with AnalyticsOptions.sessionReplayAutoStart: false.
await CSQ().startSessionReplay();Parameters
Section titled ParametersNo parameters.
CSQ().stopSessionReplay()
Section titled CSQ().stopSessionReplay()Experience Analytics | Added in: 4.2.0
Stops Session Replay on-demand.
await CSQ().stopSessionReplay();Parameters
Section titled ParametersNo parameters.
Analytics options
Section titled Analytics optionsCSQ SDK options for Product Analytics passed to CSQ().start() via StartConfig.
await CSQ().start( startConfig: StartConfig.withEnvironmentId( id: 'YOUR_ENVIRONMENT_ID', options: AnalyticsOptions( baseUrl: Uri.parse('https://example.com/'), enableInteractionsAutocapture: false, disablePageviewAutocapture: false, disablePageviewTitleAutocapture: false, disableInteractionAutocapture: false, enablePushNotificationAutocapture: false, enablePushNotificationTitleAutocapture: false, enablePushNotificationBodyAutocapture: false, sessionReplayAutoStart: true, ), ),);id (environmentId)
Section titled id (environmentId)Product Analytics environment ID. Passed as a parameter to the StartConfig.withEnvironmentId factory.
id (dataSourceId)
Section titled id (dataSourceId)Unified CSQ data source ID. Enables both Product Analytics and Experience Analytics with a single identifier. Passed as a parameter to the StartConfig.withDatasourceId factory.
baseUrl
Section titled baseUrlURI object specifying the base URI for the desired API endpoint. The SDK resolves paths using this base URI and ignores any pre-existing path elements.
disablePageviewAutocapture
Section titled disablePageviewAutocaptureWhether source pageview events will be auto-captured. Defaults to false.
disablePageviewTitleAutocapture
Section titled disablePageviewTitleAutocaptureDisable pageview title capture.
disableInteractionAutocapture
Section titled disableInteractionAutocaptureDisables autocapture of touch interactions.
enablePushNotificationAutocapture
Section titled enablePushNotificationAutocaptureWhether the SDK will auto capture interaction events on notifications. Defaults to false.
enablePushNotificationTitleAutocapture
Section titled enablePushNotificationTitleAutocaptureWhether capture the title of the notification where an interaction was performed. enablePushNotificationAutocapture must be to true.
Defaults to false.
enablePushNotificationBodyAutocapture
Section titled enablePushNotificationBodyAutocaptureWhether capture the body text of the notification where an interaction was performed. enablePushNotificationAutocapture must be to true.
Defaults to false.
enableInteractionsAutocapture
Section titled enableInteractionsAutocaptureWhether to enable automatic capture of Flutter UI interactions. Defaults to false.
sessionReplayAutoStart
Section titled sessionReplayAutoStartWhether Session Replay starts automatically at SDK launch. Defaults to true.
Set to false to disable automatic start and control Session Replay manually with CSQ().startSessionReplay() and CSQ().stopSessionReplay().