From Heap SDK to CSQ SDK

This guide provides a step-by-step upgrade process from your current installation of Heap Mobile to the latest version of the CSQ SDK.

Heap Core SDK

Heap Core SDK

CSQ 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.

Increment the Contentsquare SDK in pubspec.yaml to the latest version.

dependencies:
heap_flutter_bridge: ^0.4.0
heap_flutter_autocapture: ^0.6.0
contentsquare: ^4.0.0

Sync your dependencies by running flutter pub get.

Replace the Contentsquare SDK import with a CSQ SDK import.

import 'package:heap_flutter_bridge/heap_flutter_bridge.dart';
import 'package:heap_flutter_autocapture/heap_flutter_autocapture.dart';
import 'package:contentsquare/csq.dart';
  1. Delete Heap().startRecording() and migrate options to CSQ().configureProductAnalytics().

    main.dart
    import 'package:contentsquare/csq.dart';
    void main() async {
    await Heap().startRecording('YOUR_ENVIRONMENT_ID', {
    // your previous options
    });
    await CSQ().configureProductAnalytics(
    environmentId: 'YOUR_ENVIRONMENT_ID',
    options: ProductAnalyticsOptions(
    // Migrate options here
    ),
    );
    }
  2. Start the CSQ SDK.

    main.dart
    import 'package:contentsquare/csq.dart';
    void main() async {
    await CSQ().configureProductAnalytics(
    environmentId: 'YOUR_ENVIRONMENT_ID',
    );
    await CSQ().start();
    }
  3. Remove HeapAutocapture registration:

    await HeapAutocapture.register();
  4. Recommended In order to enable automatic capture of user interactions, add the option enableInteractionsAutocapture: true to your ProductAnalyticsOptions configuration:

    main.dart
    import 'package:contentsquare/csq.dart';
    void main() async {
    await CSQ().configureProductAnalytics(
    environmentId: 'YOUR_ENVIRONMENT_ID',
    options: ProductAnalyticsOptions(
    enableInteractionsAutocapture: true,
    ),
    );
    await CSQ().start();
    }
  5. Recommended To capture screen views automatically, add the CSQNavigatorObserver to your app’s navigator observers:

    main.dart
    import 'package:contentsquare/csq.dart';
    MaterialApp(
    navigatorObservers: [
    CSQNavigatorObserver(),
    ],
    home: MyHomePage(),
    )
    More details in Track screens.

Implement 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:

main.dart
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'),
),
),
);
}
}

Search 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.

Heap().startRecording()
CSQ().start()

For more information on SDK methods, see the SDK API reference.

GDPR / Identification

Heap SDKCSQ SDK
Heap().identify(string)CSQ().identify(userIdentifier: String)
Heap().resetIdentity()CSQ().resetIdentity()
Heap().getUserId()CSQ().metadata.userId
Heap().getSessionId()CSQ().metadata.sessionId
Heap().getEnvironmentId()CSQ().metadata.environmentId
Heap().getIdentity()CSQ().metadata.identity

Logging

Heap SDKCSQ SDK
Heap().setLogLevel(LogLevel)CSQ().debug.logLevel { get set }

Property tracking

Heap SDKCSQ SDK
Heap().addUserProperties(Map<String, dynamic>)CSQ().addUserProperties(properties: Map<String, dynamic>)
Heap().addEventProperties(Map<String, dynamic>)CSQ().addEventProperties(properties: Map<String, dynamic>)
Heap().removeEventProperty(name: String)CSQ().removeEventProperty(name: String)
Heap().clearEventProperties()CSQ().clearEventProperties()

Event tracking

Heap SDKCSQ SDK
Heap().track(String, [Map<String, dynamic>])CSQ().trackEvent(eventName: String, properties: Map<String, dynamic>?)

Personal Data Handling and Masking

Heap SDKCSQ SDK
HeapRedact(redact: bool)CSQMask(config: CSQMaskingConfig(maskTexts: true))
HeapIgnore(ignore: bool)CSQMask(config: CSQMaskingConfig(maskInteractions: true))

SDK initialization and manipulation

Heap SDKCSQ SDK
Heap().startRecording(id, options)CSQ().configureProductAnalytics(environmentID: String, options: ProductAnalyticsOptions)+CSQ().start()`
Heap().stopRecording(deleteUser = true)CSQ().stop()
Heap().stopRecording(deleteUser = false)CSQ().pauseTracking()