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.optIn6.0.0
Get user consent.
Calling this API generates a user ID and initiates tracking.
CSQ.optIn();CSQ.optOut
Section titled CSQ.optOut6.0.0
Revoke user consent, remove stored userID.
Stop CSQ SDK, flush, and clear all data.
CSQ.optOut();CSQ.identify
Section titled CSQ.identifyProduct Analytics | Added in: 6.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.
CSQ.identify("user_identity");Parameters
Section titled Parameters-
identity string (<= 100 chars)
Identity to be associated with the current user.
CSQ.resetIdentity
Section titled CSQ.resetIdentity6.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.
CSQ.resetIdentity();CSQ.sendUserIdentifier
Section titled CSQ.sendUserIdentifierExperience Analytics | Added in: 6.0.0
Associate the user identifier to the session.
CSQ.sendUserIdentifier("any_identifier")Parameters
Section titled Parameters-
userIdentifier string
The user identifier to track. Should be max 100 characters long.
CSQ.onMetadataChange
Section titled CSQ.onMetadataChange6.0.0
Get all the information related to the user and project. Refer to the CSQMetadata object.
CSQ.onMetadataChange(callback: (metadata: CSQMetadata) => void) => { // Handle metadata change});Parameters
Section titled Parameters-
callback (metadata: CSQMetadata) => void
Callback function triggered when metadata changes.
CSQMetadata
Section titled CSQMetadataCSQMetadata object contains information related to the user and project.
interface CSQMetadata { userID: string | null; sessionID: string | null; identity: string | null; environmentID: string | null; projectID: string | null; sessionReplayURL: string | null;}userID
Section titled userIDIdentifier of the current user. This is an identifier from Product Analytics by default or Experience Analytics if PA is not active.
sessionID
Section titled sessionIDSession identifier. This is an identifier from Experience Analytics by default or Product Analytics if Experience Analytics is not active.
projectID
Section titled projectIDProject identifier for Experience Analytics.
environmentID
Section titled environmentIDEnvironment identifier for Product Analytics.
sessionReplayURL
Section titled sessionReplayURLURL of current Session Replay.
identity
Section titled identityIdentity associated with the user by calling identify().
Property Tracking
Section titled Property TrackingCSQ.addDynamicVar
Section titled CSQ.addDynamicVarExperience Analytics | Added in: 6.0.0
Adds dynamic variables to the session properties.
This method allows you to pass a key and a value parameters, representing a key-value pair
that is scoped to the session. You can also add, as a last parameter, a function that we will
call so you can handle it gracefully
CSQ.addDynamicVar("key1", "value1")CSQ.addDynamicVar("key2", 2, (errorObject) => { console.log(errorObject.toString());});Parameters
Section titled Parameters-
key string
Dynamic variable key
-
value string
Dynamic variable value
-
callback (error: Error) => void (optional)
Optional callback function to handle errors.
CSQ.addUserProperties
Section titled CSQ.addUserPropertiesProduct Analytics | Added in: 6.0.0
Add a collection of properties to be associated with the current user.
CSQ.addUserProperties({ propertyKey: "propertyValue",});Parameters
Section titled Parameters-
properties Record<string, PropertyValue
A dictionary of user properties.
PropertyValuecan benumber,string,boolean,bigint
CSQ.addEventProperties
Section titled CSQ.addEventPropertiesProduct Analytics | Added in: 6.0.0
Add a collection of properties to be associated with all future events.
CSQ.addEventProperties({ propertyKey: "propertyValue",});Parameters
Section titled Parameters-
properties Record<string, PropertyValue>
A dictionary of event properties.
PropertyValuecan benumber,string,boolean,bigint
CSQ.removeEventProperty
Section titled CSQ.removeEventPropertyProduct Analytics | Added in: 6.0.0
Removes a single property from the collection of event-wide properties.
CSQ.removeEventProperty("propertyKey")Parameters
Section titled Parameters-
name string
The key of the property to remove.
CSQ.clearEventProperties
Section titled CSQ.clearEventPropertiesProduct Analytics | Added in: 6.0.0
Removes all event-wide properties.
CSQ.clearEventProperties()CSInApp
Section titled CSInAppCSQ.handleUrl
Section titled CSQ.handleUrlExperience Analytics | Added in: 6.0.0
Allows the Contentsquare SDK to monitor CS in-app features activation through a custom URL scheme.
For more details check our CSInApp documentation.
CSQ.handleUrl("sample_url")Parameters
Section titled Parameters-
urlString string | null | undefined
The URL handled by React Native Linking API ↗.
Interoperability
Section titled Interoperability<CSQWebView>
Section titled <CSQWebView>Experience Analytics | Added in: 6.0.0
Allows Contentsquare SDK to track webviews.
<CSQWebView> <WebView source={{ uri: "https://test-url.com", }} /></CSQWebView>Parameters
Section titled Parameters-
children ReactElement
The webview to register for tracking. CSQWebView supports react-native-webview ↗.
Event Tracking
Section titled Event TrackingCSQ.trackTransaction
Section titled CSQ.trackTransactionExperience Analytics | Added in: 6.0.0
Send a transaction.
CSQ.trackTransaction(10, Currency.EUR, "transactionId");Parameters
Section titled Parameters-
value number
The monetary value of the transaction.
-
currency Currency | string
The ISO 4217 currency code of the transaction.
-
transactionId string | null (optional)
An optional identifier for the transaction.
CSQ.trackScreenview
Section titled CSQ.trackScreenview6.0.0
Send a screen view with or without custom variables. Requires Experience Analytics to be started.
CSQ.trackScreenview(name: "ScreenName", cvars: [{index: 0, key: "key", value: "value"}])Parameters
Section titled Parameters-
name String
The name of the screen.
-
cvars CustomVar[] (optional)
An array of custom variables to attach to the screen view.
index number
Custom variable index
key string (<= 512 chars)
Custom variable key
value string (<= 256 chars)
Custom variable value
CSQ.trackEvent
Section titled CSQ.trackEventProduct Analytics | Added in: 6.0.0
Creates an event message to be tracked and sent to the API.
CSQ.trackEvent('event', { some_property: 100 });Parameters
Section titled Parameters-
eventName string
The name of the event to be tracked.
-
properties Record<string, PropertyValue> (optional)
Optional properties to associate with the event.
PropertyValuecan benumber,string,boolean, orbigint.
Logging
Section titled LoggingCSQ.logToConsole
Section titled CSQ.logToConsoleProduct Analytics | Added in: 6.0.0
Enables logging to the console for Product Analytics events and diagnostics.
CSQ.logToConsole();CSQ.setLogChannel
Section titled CSQ.setLogChannelProduct Analytics | Added in: 6.0.0
Sets the log channel for Product Analytics logging.
import { LogChannel } from '@contentsquare/react-native-bridge';
CSQ.setLogChannel(LogChannel.LOG);Parameters
Section titled Parameters-
logChannel LogChannel
The log channel to use. Available values:
LogChannel.LOGLogChannel.TRACELogChannel.DEBUGLogChannel.INFOLogChannel.WARNLogChannel.ERRORLogChannel.NONE
CSQ.setLogLevel
Section titled CSQ.setLogLevelProduct Analytics | Added in: 6.0.0
Sets the log level for Product Analytics logging.
import { LogLevel } from '@contentsquare/react-native-bridge';
CSQ.setLogLevel(LogLevel.INFO);Parameters
Section titled Parameters-
logLevel LogLevel
The log level to use. Available values:
LogLevel.TRACELogLevel.DEBUGLogLevel.INFOLogLevel.WARNLogLevel.ERRORLogLevel.NONE
Error tracking
Section titled Error trackingCSQ.setUrlMaskingPatterns
Section titled CSQ.setUrlMaskingPatternsExperience Analytics | Added in: 6.0.0
Sets URL masking patterns.
CSQ.setUrlMaskingPatterns(["pattern1", "pattern2"])Parameters
Section titled Parameters-
patterns string[]
A list of URL patterns to mask.
CSQ.triggerNativeCrash
Section titled CSQ.triggerNativeCrashExperience Analytics | Added in: 6.0.0
Trigger a native crash for testing purposes.
CSQ.triggerNativeCrash()Session Replay
Section titled Session ReplayCSQ.startSessionReplay
Section titled CSQ.startSessionReplay6.3.0
Starts Session Replay. Use this when you have set sessionReplayAutoStart to false to manually control when Session Replay starts. Calling this method does not force Session Replay collection — it enables the module to begin evaluating sampling rules.
import { CSQ } from "@contentsquare/react-native-bridge";
CSQ.startSessionReplay();CSQ.stopSessionReplay
Section titled CSQ.stopSessionReplay6.3.0
Stops Session Replay collection. Any data collected before this call is preserved and uploaded according to the SDK upload schedule.
import { CSQ } from "@contentsquare/react-native-bridge";
CSQ.stopSessionReplay();Personal Data/Masking
Section titled Personal Data/MaskingCSQ.setDefaultMasking
Section titled CSQ.setDefaultMaskingExperience Analytics | Added in: 6.0.0
Set the default masking state.
All Views are fully masked by default.
CSQ.setDefaultMasking(true)Parameters
Section titled Parameters-
masked Bool
The default masking state to be set.
<CSQMask>
Section titled <CSQMask>6.0.0
Allows to mask content for Session Replay and suppress events for view inside <CSQMask> and all its children.
By default, Session Replay masking is enabled, and event tracking is disabled.
<CSQMask> <View> ... </View></CSQMask>Props
Section titled Props-
isSessionReplayMasked boolean
The view which content will be masked.
-
ignoreTextOnly boolean
Product AnalyticsThis will ignore text and accessibility labels inside the masked view for event tracking.
-
allowInnerHierarchy boolean
Product AnalyticsAllows the full hierarchy to be exposed, but without properties or text capture.
-
allowProps boolean
Product AnalyticsAllows property capture, but will exclude text-containing properties if the below options are omitted.
-
allowText boolean
Product AnalyticsAllows text capture. It can be used alongside
allowPropsto expose text-containing properties. -
allowAccessibilityLabel boolean
Product AnalyticsAllows
accessibilityLabelcapture. -
children ReactElement
The view which masking rules will be applied to.
WithCSQMask
Section titled WithCSQMaskHigher Order Component (HOC) to mask content for Session Replay and suppress events for view inside WithCSQMask and all its children.
Props
Section titled Props-
WrappedComponent ReactElement
The component which masking rules will be applied to.
-
maskOptions CSQMaskProps
Masking options to be applied to the wrapped component.
-
isSessionReplayMasked boolean
The view which content will be masked.
-
ignoreTextOnly boolean
Product AnalyticsThis will ignore text and accessibility labels inside the masked view for event tracking.
-
allowInnerHierarchy boolean
Product AnalyticsAllows the full hierarchy to be exposed, but without properties or text capture.
-
allowProps boolean
Product AnalyticsAllows property capture, but will exclude text-containing properties if the below options are omitted.
-
allowText boolean
Product AnalyticsAllows text capture. It can be used alongside
allowPropsto expose text-containing properties. -
allowAccessibilityLabel boolean
Product AnalyticsAllows
accessibilityLabelcapture.
SDK Initialization and Management
Section titled SDK Initialization and ManagementCSQ.configureProductAnalytics
Section titled CSQ.configureProductAnalyticsDeprecated | Product Analytics | Added in: 6.0.0
Product Analytics is now configured using the options parameter of start().
CSQ.start
Section titled CSQ.start6.0.0
Start and configure the SDK. Use StartConfig to specify the product configuration.
import { CSQ, StartConfig } from '@contentsquare/react-native-bridge';
// Experience Analytics only (DXA)CSQ.start(StartConfig.dxa());
// Product Analytics (Standalone)CSQ.start(StartConfig.withEnvironmentId("YOUR_ENVIRONMENT_ID"));
// Product Analytics (Unified CSQ)CSQ.start(StartConfig.withDataSourceId("YOUR_DATASOURCE_ID"));
// Product Analytics with optionsCSQ.start(StartConfig.withEnvironmentId("YOUR_ENVIRONMENT_ID", { enableRNAutocapture: true}));StartConfig
Section titled StartConfig-
StartConfig.dxa() CSQConfig
Start the SDK with Experience Analytics (DXA) only.
-
StartConfig.withEnvironmentId(id, options?) CSQConfig
Start the SDK with Product Analytics using an environment ID.
id(string) — Your Product Analytics environment ID.options(AnalyticsOptions, optional) — Product Analytics initialization options.
-
StartConfig.withDataSourceId(id, options?) CSQConfig
Start the SDK with Product Analytics using a data source ID (Unified CSQ).
id(string) — Your Unified CSQ data source ID.options(AnalyticsOptions, optional) — Product Analytics initialization options.
CSQ.stop
Section titled CSQ.stop6.0.0
Stop all activity from the SDK.
Once run no requests, telemetry collection, or logs will be generated.
CSQ.stop();CSQ.pauseTracking
Section titled CSQ.pauseTracking6.0.0
Pause all tracking features.
CSQ.pauseTracking();CSQ.resumeTracking
Section titled CSQ.resumeTracking6.0.0
Resume all tracking features.
CSQ.resumeTracking();Product Analytics initialization options
Section titled Product Analytics initialization optionsCSQ SDK options for Product Analytics passed to start().
type AnalyticsOptions = { enableRNAutocapture?: boolean; disableInteractionAutocapture?: boolean; disablePageviewAutocapture?: boolean; baseUrl?: string; uploadInterval?: number; disableInteractionTextCapture?: boolean; disableInteractionAccessibilityLabelCapture?: boolean; sessionReplayAutoStart?: boolean; // Native specific options enablePushNotificationAutocapture?: boolean; enablePushNotificationTitleAutocapture?: boolean; enablePushNotificationBodyAutocapture?: boolean; enableViewAutocapture?: boolean; // iOS specific options disablePageviewTitleAutocapture?: boolean;};React Native Product Analytics initialization options
Section titled React Native Product Analytics initialization optionsenableRNAutocapture
Section titled enableRNAutocaptureEnable React Native view autocapture.
Defaults to false.
disableInteractionAutocapture
Section titled disableInteractionAutocaptureDisables autocapture of touch events on React Native Views.
Defaults to false.
disablePageviewAutocapture
Section titled disablePageviewAutocaptureWhether source pageview events will be auto-captured. Defaults to false.
baseUrl
Section titled baseUrlURI specifying the base URL for the desired API endpoint.
uploadInterval
Section titled uploadIntervalThe interval, in milliseconds, between event uploads.
disableInteractionTextCapture
Section titled disableInteractionTextCaptureDisables text capture for React Native interactions. Defaults to false.
disableInteractionAccessibilityLabelCapture
Section titled disableInteractionAccessibilityLabelCaptureDisables accessibility label capture for React Native interactions. Defaults to false.
sessionReplayAutoStart
Section titled sessionReplayAutoStartWhether the SDK starts Session Replay automatically when the SDK starts. When set to false, you must call CSQ.startSessionReplay() to start Session Replay.
Defaults to true.
Native specific Product Analytics initialization options
Section titled Native specific Product Analytics initialization optionsenablePushNotificationAutocapture
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.
enableViewAutocapture
Section titled enableViewAutocaptureWhether the SDK will auto capture UI interactions and source pageviews. Defaults to false.
iOS specific Product Analytics initialization options
Section titled iOS specific Product Analytics initialization optionsdisablePageviewTitleAutocapture
Section titled disablePageviewTitleAutocaptureDisable pageview title capture.