From Contentsquare SDK to CSQ SDK
This guide provides a step-by-step upgrade process from your current installation of Contentsquare Mobile SDK to the latest version of the CSQ SDK.
Contentsquare SDK
CSQ SDK
The latest version of our SDK provides a unified set of APIs for Product Analytics, Experience Analytics, and Experience Monitoring, eliminating redundant APIs that perform the same actions.
Upgrading to the latest version ensures you benefit from all our newest features and product enhancements.
Dependency upgrades
Section titled Dependency upgradesIncrement the Contentsquare SDK in pubspec.yaml to the latest version.
dependencies: contentsquare: ^3.19.1 contentsquare: ^4.0.0Sync your dependencies by running flutter pub get.
Imports updates
Section titled Imports updatesReplace the Contentsquare SDK import with a CSQ SDK import.
import 'package:contentsquare/contentsquare.dart';import 'package:contentsquare/csq.dart';SDK start
Section titled SDK start-
Optional: If you were usingContentsquareRootwidget - remove it from your widget tree.main.dart void main() {runApp(const MyApp());}class MyApp extends StatelessWidget {@overrideWidget build(BuildContext context) {return ContentsquareRoot(child: MaterialApp(return MaterialApp(title: 'My Flutter App',home: Home()),);}} -
Start the CSQ SDK manually.
If you were using before manual start by calling
Contentsquare().start(), simply replace it withCSQ().start():main.dart import 'package:contentsquare/csq.dart';void main() async {await Contentsquare().start();await CSQ().start();}If you were relying on
ContentsquareRoot, you need from now on always start the SDK manually. Ideally the SDK should be started as soon as possible, for example from themain()function:import title="main.dart" 'package:contentsquare/csq.dart';void main() async {await CSQ().start();} -
(Optional) If you were relying on the Contentsquare SDK autostart, remove the
CSDisableAutostartproperty and calls toContentsquare.start().Info.plist <key>CSDisableAutostart</key><true/>AppDelegate.swift Contentsquare.start()Info.plist <key>CSDisableAutostart</key><true/>AppDelegate.m [Contentsquare start]; -
(Optional) If you have chosen to deactivate the autostart of the Contentsquare SDK, you can now remove the entry in the manifest, as the CSQ SDK doesn’t have an autostart.
AndroidManifest.xml <application>...<meta-dataandroid:name="com.contentsquare.android.autostart"android:value="false"/>...</application>
Get user consent
Section titled Get user consentImplement the optIn() API to forward user consent to the SDK and generate a user ID.
The CSQ SDK treats users as opted-out by default.
It can be done immediately after start is called:
void main() async { // ... await CSQ().start(); await CSQ().optIn(); // ...}Alternatively, you can call optIn() in response to a user action, such as tapping an “I agree” button:
class UserConsentScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('User Consent'), ), body: Center( child: ElevatedButton( onPressed: () async { await CSQ().optIn(); }, child: Text('Agree with Terms and Conditions'), ), ), ); }}Update APIs
Section titled Update APIsSearch and replace all legacy SDK API calls in your app to the latest CSQ APIs using the following mappings. Updating your API calls ensures continued functionality without disruption.
In most cases, this process consists in updating the namespace and method names, with no changes to parameters.
Contentsquare().start()CSQ().start()For more information on SDK methods, see the SDK API reference.
GDPR / Identification
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare().optIn() | CSQ().optIn() |
Contentsquare().optOut() | CSQ().optOut() |
Contentsquare().sendUserIdentifier() | CSQ().sendUserIdentifier() |
Contentsquare().getUserId() | CSQ().metadata.userID |
Contentsquare().forgetMe()
You can use CSQ().optOut() instead to forget user id and stop tracking. If needed call CSQ().optIn() when you want to resume tracking.
Property tracking
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare().sendDynamicVar(key: String, intValue: int). | CSQ().addDynamicVar(DynamicVar.fromIn(key: String, value: int)) |
Contentsquare().sendDynamicVar(key: String, stringValue: String). | CSQ().addDynamicVar(DynamicVar.fromString(key: String, value: String)) |
CSInApp (iOS only)
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare.handle(url: URL) | CSQ.handle(url: URL) |
Contentsquare.csInApp | CSQ.csInApp |
Interoperability
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare().onSessionReplayLinkChange(callback) | CSQ().metadata.onChange(Metadata) |
Contentsquare().currentSessionReplayUrl | CSQ().metadata.onChange(Metadata) |
Contentsquare().setURLMaskingPatterns() | CSQ().setURLMaskingPatterns() |
ContentsquareNavigatorObserver(). | CSQNavigatorObserver() |
ContentsquareWebViewWrapper(). | CSQWebViewWrapper() |
Event tracking
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare.sendTransaction(double, String, String, String?) | CSQ.trackTransaction(Transaction(price: double, currency: Currency, id: String)) |
Contentsquare.send(String) | CSQ.trackScreenview(screenName: String) |
Contentsquare.send(String, List<CustomVar>?) | CSQ.trackScreenview(screenName: String, customVars: List<CustomVar>) |
Error tracking
| Contentsquare SDK | CSQ SDK |
|---|---|
ContentsquareHttpOverrides() | CSQHttpOverrides() |
Contentsquare().collectFlutterError(details: FlutterErrorDetails, presentErrorDetails: bool) | CSQ().collectFlutterError(details: FlutterErrorDetails, presentErrorDetails: bool). |
Contentsquare().collectError(error: Object, stackTrace: StackTrace) | CSQ().collectError(error: Object, stackTrace: StackTrace) |
Personal Data Handling and Masking
| Contentsquare SDK | CSQ SDK |
|---|---|
MaskingConfig() | CSQMaskingConfig() |
SessionReplayMaskingScope | CSQMask |
SDK initialization and manipulation
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare().start() | CSQ().start() |
Contentsquare().stopTracking() | CSQ().pauseTracking() |
Contentsquare().resumeTracking() | CSQ().resumeTracking() |
Contentsquare().triggerReplayForCurrentSession(name: String) | CSQ().triggerReplayForCurrentSession(name: String) |
Contentsquare().triggerReplayForCurrentScreen(name: String) | CSQ().triggerReplayForCurrentScreen(name: String) |