From Heap Core SDK + Contentsquare SDK to CSQ SDK
This guide provides a step-by-step upgrade process from your current installation of Contentsquare and Heap Mobile to the latest version of the CSQ SDK.
Heap Core 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 upgradesReplace Heap and Contentsquare SDK dependencies by the CSQ SDK:
implementation("io.heap.core:heap-android-core:0.8.+")implementation("io.heap.contentsquare.csbridge:contentsquare-bridge:0.8.+)implementation("io.heap.autocapture:heap-autocapture-view:0.8.+")implementation("io.heap.autocapture:heap-autocapture-compose:0.8.+")implementation("com.contentsquare.android:library:4.39.1")implementation("com.contentsquare.android:compose:4.39.1")implementation("com.contentsquare.android:sdk:1.10.0")implementation("com.contentsquare.android:sdk-compose:1.10.0")implementation 'io.heap.core:heap-android-core:0.8.+'implementation 'io.heap.contentsquare.csbridge:contentsquare-bridge:0.8.+'implementation 'io.heap.autocapture:heap-autocapture-view:0.8.+'implementation 'io.heap.autocapture:heap-autocapture-compose:0.8.+'implementation 'com.contentsquare.android:library:4.39.1'implementation 'com.contentsquare.android:sdk-compose:4.39.1'implementation 'com.contentsquare.android:sdk:1.10.0'implementation 'com.contentsquare.android:sdk-compose:1.10.0'Library imports
Section titled Library importsReplace the Heap and Contentsquare dependency imports with a CSQ SDK import.
import io.heap.core.Heapimport io.heap.autocapture.ViewAutocaptureSDKimport io.heap.contentsquare.csbridge.HeapContentsquareIntegrationimport com.contentsquare.android.Contentsquareimport com.contentsquare.CSQSDK start
Section titled SDK startFollow these steps to start the CSQ SDK with your current configuration.
Delete
Heap.startRecording()and migrate configuration options toCSQ.start().- Standalone
- Unified CSQ
Onboard to Unified CSQ, our latest, all-in-one platform offering.
Reach out to your Customer Success Manager for more information.
MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQclass MyApplication : Application() {override fun onCreate() {super.onCreate()Heap.startRecording(context = this,"YOUR_ENVIRONMENT_ID",Options(// ...options))CSQ.start(context = this,StartConfig.withEnvironmentId(id = "YOUR_ENVIRONMENT_ID",options = AnalyticsOptions(// ...options)))}}MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQclass MyApplication : Application() {override fun onCreate() {super.onCreate()Heap.startRecording(context = this,"YOUR_ENVIRONMENT_ID",Options(// ...options))CSQ.start(context = this,StartConfig.withDataSourceId(id = "YOUR_DATASOURCE_ID",options = AnalyticsOptions(// ...options)))}}Enable Autocapture with
enableViewAutocapture = trueand remove the call toViewAutocaptureSDK.register()- Standalone
- Unified CSQ
Onboard to Unified CSQ, our latest, all-in-one platform offering.
Reach out to your Customer Success Manager for more information.
MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQclass MyApplication : Application() {override fun onCreate() {super.onCreate()ViewAutocaptureSDK.register()CSQ.start(context = this,StartConfig.withEnvironmentId(id = "YOUR_ENVIRONMENT_ID",options = AnalyticsOptions(// ...optionsenableViewAutocapture = true)))}}MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQclass MyApplication : Application() {override fun onCreate() {super.onCreate()ViewAutocaptureSDK.register()CSQ.start(context = this,StartConfig.withDataSourceId(id = "YOUR_DATASOURCE_ID",options = AnalyticsOptions(// ...optionsenableViewAutocapture = true)))}}(Optional) For Autocapture Jetpack Compose, register the Compose Autocapture SDK.
- Standalone
- Unified CSQ
Onboard to Unified CSQ, our latest, all-in-one platform offering.
Reach out to your Customer Success Manager for more information.
MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQimport io.heap.autocapture.compose.ComposeAutocaptureSDKclass MyApplication : Application() {override fun onCreate() {super.onCreate()ComposeAutocaptureSDK.register()CSQ.start(context = this,StartConfig.withEnvironmentId(id = "YOUR_ENVIRONMENT_ID",options = AnalyticsOptions(// ...optionsenableViewAutocapture = true)))}}MyApplication.kt import android.app.Applicationimport com.contentsquare.CSQimport io.heap.autocapture.compose.ComposeAutocaptureSDKclass MyApplication : Application() {override fun onCreate() {super.onCreate()ComposeAutocaptureSDK.register()CSQ.start(context = this,StartConfig.withDataSourceId(id = "YOUR_DATASOURCE_ID",options = AnalyticsOptions(// ...optionsenableViewAutocapture = true)))}}- Remove
HeapContentsquareIntegration.bind().Sending Heap screenviews to Contentsquare
MyApplication.kt HeapContentsquareIntegration.bind(applicationContext,sendHeapPageviewsToContentsquare = true,sendContentsquareScreenviewsToHeap = false)Sending Contentsquare screenviews to Heap
- Standalone
- Unified CSQ
Onboard to Unified CSQ, our latest, all-in-one platform offering.
Reach out to your Customer Success Manager for more information.
MyApplication.kt HeapContentsquareIntegration.bind(applicationContext,sendHeapPageviewsToContentsquare = false,sendContentsquareScreenviewsToHeap = true)CSQ.start(context = this,StartConfig.withEnvironmentId(id = "YOUR_ENVIRONMENT_ID",options = AnalyticsOptions(disablePageviewAutocapture = true)))MyApplication.kt HeapContentsquareIntegration.bind(applicationContext,sendHeapPageviewsToContentsquare = false,sendContentsquareScreenviewsToHeap = true)CSQ.start(context = this,StartConfig.withDataSourceId(id = "YOUR_DATASOURCE_ID",options = AnalyticsOptions(disablePageviewAutocapture = true))) - (Optional) For Autocapture notifications, replace
NotificationAutocaptureSDK.register()with these options:- Standalone
- Unified CSQ
Onboard to Unified CSQ, our latest, all-in-one platform offering.
Reach out to your Customer Success Manager for more information.
MyApplication.kt NotificationAutocaptureSDK.register(captureTitleText = true,captureBodyText = true)CSQ.start(context = this,StartConfig.withEnvironmentId(id = "YOUR_ENVIRONMENT_ID",options = AnalyticsOptions(// ...optionsenablePushNotificationAutocapture = true,enablePushNotificationTitleAutocapture = true,enablePushNotificationBodyAutocapture = true)))MyApplication.kt NotificationAutocaptureSDK.register(captureTitleText = true,captureBodyText = true)CSQ.start(context = this,StartConfig.withDataSourceId(id = "YOUR_DATASOURCE_ID",options = AnalyticsOptions(// ...optionsenablePushNotificationAutocapture = true,enablePushNotificationTitleAutocapture = true,enablePushNotificationBodyAutocapture = true))) (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, generate a user ID, and initiate tracking.
import android.app.Applicationimport com.contentsquare.CSQ
class MyApplication : Application() { override fun onCreate() { super.onCreate() CSQ.start(this) }}
// ConsentActivityval optinButton: Button = findViewById(R.id.btn_accept_tracking)
optinButton.setOnClickListener { CSQ.optIn() startActivity(Intent(this, MainActivity::class.java))}Once tracking has started, you're able to take full advantage of the CSQ SDK API to identify users, track custom events, and more.
Contentsquare's Product Analytics module will also automatically start tracking a wide range of user interactions, view controller changes, and app version changes without any additional code.
Transactions
Section titled Transactions-
Update your transaction imports:
import com.contentsquare.android.api.model.Transactionimport com.contentsquare.api.model.Transaction -
Update your currency imports:
import com.contentsquare.android.api.Currenciesimport com.contentsquare.api.model.Currency -
Replace the currency type from
InttoCurrencyenum:val currency: Int = Currencies.USDval currency: Currency = Currency.USD -
Replace
Transaction.builderbyTransactionandContentsquare.send()byCSQ.trackTransaction():val builder = Transaction.builder(100f, Currency.EUR).id("optionalId")Contentsquare.send(builder.build())val transaction = Transaction(100f, Currency.EUR, "optionalId")CSQ.trackTransaction(transaction)
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.
Contentsquare.start(this)Heap.startRecording("YOUR_ENVIRONMENT_ID")CSQ.start(this, StartConfig.withEnvironmentId("YOUR_ENVIRONMENT_ID"))For more information on SDK methods, see the SDK API reference.
Product Analytics
Section titled Product AnalyticsGDPR / Identification
| Heap Core SDK | CSQ SDK |
|---|---|
Heap.identify(identity: String) | CSQ.identify(identity: 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 Core SDK | CSQ SDK |
|---|---|
import io.heap.core.logs.LogLevel | import com.contentsquare.api.contract.LogLevel |
Heap.setLogLevel() | CSQ.debug.logLevel = LogLevel.{LEVEL}Possible values:
|
import io.heap.core.logs.LogChannel | import com.contentsquare.api.contract.LogChannel |
Heap.setLogChannel(logChannel: LogChannel) | interface LogChannelCSQ.debug.logChannel = LogChannel() |
Property tracking
| Heap Core SDK | CSQ SDK |
|---|---|
Heap.addUserProperties(properties: Map<String, Any>) | CSQ.addUserProperties(properties: Map<String, Any>) |
Heap.addEventProperties(properties: Map<String, Any>) | CSQ.addEventProperties(properties: Map<String, Any>) |
Heap.removeEventProperty(name: String) | CSQ.removeEventProperty(name: String) |
Heap.clearEventProperties() | CSQ.clearEventProperties() |
import io.heap.core.api.contract.HeapProperty | import com.contentsquare.api.contract.Property |
Event tracking
| Heap Core SDK | CSQ SDK |
|---|---|
Heap.trackPageview() | CSQ.trackScreenview(name: String, customVars: List<CustomVar>) |
Heap.track() | CSQ.trackEvent(name: String, properties: Map<String, PropertyValue>?) |
Personal Data Handling and Masking
| Heap Core SDK | CSQ SDK |
|---|---|
ViewAutocaptureSDK.ignoreInteractions(view: View) | CSQ.ignoreInteractions(view: View) |
ViewAutocaptureSDK.redactText(view: View) | CSQ.mask(view: View) |
view.setTag(R.id.heapRedactText, false) | CSQ.unmask(view: View) |
Initialization options disableInteractionTextCapture and disableInteractionAccessibilityLabelCapture | CSQ.maskTexts(mask: Boolean) |
Jetpack compose
| Heap Core SDK | CSQ SDK |
|---|---|
@Composable | @Composable |
@Composable | @Composable |
SDK initialization and manipulation
| Heap Core SDK | CSQ SDK |
|---|---|
import io.heap.core.Options | import com.contentsquare.api.model.AnalyticsOptions |
| Heap SDK initialization options | CSQ.start(context, StartConfig.withEnvironmentId(id = "envId", options = AnalyticsOptions()))See supported options for more information. |
Heap.startRecording(context: Context, envId: String, options: Options) | CSQ.start(context, StartConfig.withEnvironmentId(id = "envId", options = AnalyticsOptions())) |
Heap.startRecording(context: Context, envId: String, options: Options) with resumePreviousSession = true | CSQ.resumeTracking() |
Heap.stopRecording() | CSQ.stop() or CSQ.pauseTracking() |
Heap.stopRecording(deleteUser = true) | CSQ.stop() + CSQ.optOut() |
Experience Analytics
Section titled Experience AnalyticsGDPR / Identification
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare.optIn(context: Context) | CSQ.optIn() |
Contentsquare.optOut(context: Context) | CSQ.optOut() |
Contentsquare.getUserId() | CSQ.metadata.userId |
Contentsquare.getProjectId() | CSQ.metadata.projectId |
Contentsquare.getSessionNumber() | CSQ.metadata.sessionId |
Contentsquare.sendUserIdentifier(identifier: String) | CSQ.sendUserIdentifier(identifier: String) |
Property tracking
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare.send(key: String, value: Long) | CSQ.addDynamicVar(key: String, value: Long) |
Contentsquare.send(key: String, value: String) | CSQ.addDynamicVar(key: String, value: String) |
View tracking
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare.excludeFromExposureMetric(view: View) | CSQ.excludeFromExposureMetric(view: View) |
Interoperability
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare.onSessionReplayLinkChange(callback: Consumer<String>) | CSQ.metadata.onChanged(metadata: Metadata) |
CsWebViewManager.injectEventTrackingInterface(webView: WebView) | CSQ.registerWebView(webView: WebView) |
CsWebViewManager.removeEventTrackingInterface(webView: WebView) | CSQ.unregisterWebView(webView: WebView) |
Event tracking
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare.send(transaction: Transaction) | CSQ.trackTransaction(transaction: Transaction) |
Contentsquare.send(screenName: String) / Contentsquare.send(screenName: String, customVars: Array<CustomVar>) | CSQ.trackScreenview(name: String, customVars: List<CustomVar>) |
Contentsquare.consumeEvent(motionEvent: MotionEvent) | CSQ.trackMotionEvent(motionEvent: MotionEvent) |
| Contentsquare SDK | CSQ SDK |
|---|---|
import com.contentsquare.android.compose.analytics.TriggeredOnResumeTriggeredOnResume(block: () -> Unit) | import com.contentsquare.api.compose.screen.TriggeredOnResumeTriggeredOnResume(block: () -> Unit) |
Error tracking
| Contentsquare SDK | CSQ SDK |
|---|---|
import com.contentsquare.android.error.analysis.network.ErrorAnalysisInterceptor | import com.contentsquare.api.contract.CsqOkHttpInterceptor |
import com.contentsquare.android.error.analysis.ErrorAnalysis | import com.contentsquare.api.model.NetworkMetric |
ErrorAnalysis.setUrlMaskingPatterns(patterns: List<String>) | CSQ.setUrlMaskingPatterns(patterns: List<String>) |
ErrorAnalysis.getInstance().newNetworkMetric(url: String, httpMethod: HttpMethod) | NetworkMetric(url: String, httpMethod: HttpMethod) |
ErrorAnalysisInterceptor() | CsqOkHttpInterceptor() |
Personal Data Handling and Masking
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare.doNotTrack(vararg activitiesClasses: Class<Activity?>) | CSQ.ignoreInteractions(view: View) |
Contentsquare.setDefaultMasking(masked: Boolean) | CSQ.setDefaultMasking(masked: Boolean) |
Contentsquare.mask(view: View) | CSQ.mask(view: View) |
Contentsquare.mask(type: Class<*>) | CSQ.mask(type: Class<*>) |
Contentsquare.unMask(view: View) | CSQ.unmask(view: View) |
Contentsquare.unmask(type: Class<*>) | CSQ.unmask(type: Class<*>) |
Contentsquare.maskMenuItem(resourceID: Int) | CSQ.maskMenuItem(resourceID: Int) |
Contentsquare.unMaskMenuItem(resourceID: Int) | CSQ.unmaskMenuItem(resourceID: Int) |
Jetpack compose
| Contentsquare SDK | CSQ SDK |
|---|---|
Modifier.sessionReplayMask(enableMasking: Boolean) | @Composable |
Modifier.excludeFromGestureRecognition() | @Composable |
SDK initialization and manipulation
| Contentsquare SDK | CSQ SDK |
|---|---|
Contentsquare.start(context: Context) | CSQ.start(context: Context) |
Contentsquare.stopTracking() | CSQ.pauseTracking() |
Contentsquare.resumeTracking() | CSQ.resumeTracking() |
Number of sessions
Section titled Number of sessionsSession timeout definition changed:
- Before: 30 minutes after app goes to background
- Now: 30 minutes after last event
This may affect session counts and aligns with web and market standards.
Checklist
Section titled ChecklistCongratulations! You're all set. Use this checklist to ensure everything is correctly updated.
Ensure that your build files no longer reference
io.heap.core:heap-android-core, io.heap.autocapture:heap-autocapture-view, com.contentsquare.android:library, or
com.contentsquare.android:sdk-compose.
Your import io.heap.core.Heap,
import io.heap.autocapture.ViewAutocaptureSDK, and
com.contentsquare.android.Contentsquare; declarations have been updated to
import com.contentsquare.CSQ.
You no longer have references to Heap. (except if you are using
webviews), HeapContentsquareIntegration., or Contentsquare. methods in your codebase.
All calls to the CSQ SDK use the CSQ.namespace.
Number of sessions
Section titled Number of sessionsSession timeout definition changed:
- Before: 30 minutes after app goes to background
- Now: 30 minutes after last event
This may affect session counts and aligns with web and market standards.