From Heap Classic 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 Classic 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 the Heap Classic SDK dependency by the CSQ SDK.
yarn remove @heap/react-native-heapyarn add @contentsquare/react-native-bridgecd ios && pod installnpm uninstall@heap/react-native-heapnpm install @contentsquare/react-native-bridgecd ios && pod installLibrary imports
Section titled Library importsReplace Heap Classic imports with a CSQ SDK import.
import Heap, { HeapIgnore, HeapIgnoreTargetText, withHeapIgnore} from '@heap/react-native-heap';import { CSQ, CSQMask, withCSQMask} from "@contentsquare/react-native-bridge";After updating the import, some APIs used in your development environment may show errors. The next steps in this guide will help you update them to the latest versions.
SDK start
Section titled SDK startFollow these steps to start the CSQ SDK with your current configuration.
Migrate your app ID and the config options from
Heap.setAppId()toCSQ.configureProductAnalytics().App.tsx import { CSQ } from "@contentsquare/react-native-bridge";useEffect(() => {Heap.setAppId("YOUR_ENVIRONMENT_ID");CSQ.configureProductAnalytics("YOUR_ENVIRONMENT_ID")}, []);For React Native Autocapture, replace the babel plugin from
@heap/react-native-heapto@contentsquare/react-native-bridge/babelin your babel configuration.babel.config.js module.exports = {plugins: ['./node_modules/@heap/react-native-heap/instrumentor/src/index.js'],plugins: ['@contentsquare/react-native-bridge/babel'],};babel.config.json {"plugins": ["./node_modules/@heap/react-native-heap/instrumentor/src/index.js","@contentsquare/react-native-bridge/babel"]}Remove Heap from
app.jsonplugins arrayapp.json {"plugins": ["@heap/react-native-heap"]}Remove
Heap.withReactNavigationAutotrack()from navigationJavaScript import Heap from '@heap/react-native-heap';const HeapNavigationContainer = Heap.withReactNavigationAutotrack(NavigationContainer);To start Autocapture set
enableRNAutocapture = trueoption:App.tsx import { CSQ } from "@contentsquare/react-native-bridge";useEffect(() => {CSQ.configureProductAnalytics("YOUR_ENVIRONMENT_ID",{enableRNAutocapture: true})}, []);Add a call to
CSQ.start()after the configuration call.App.tsx import { CSQ } from "@contentsquare/react-native-bridge";useEffect(() => {CSQ.configureProductAnalytics("YOUR_ENVIRONMENT_ID",{enableRNAutocapture: true})CSQ.start();}, []);
Get user consent
Section titled Get user consentThe CSQ SDK treats users as opted-out by default.
Implement the optIn() API to forward user consent to the SDK and generate a user ID.
import React, { useState } from "react";import { View, Text, Button } from "react-native";import { CSQ } from "@contentsquare/react-native-bridge";
const PolicyConsentScreen = () => { const [isTrackingAccepted, setIsTrackingAccepted] = useState(false);
const handleAcceptPolicy = () => { setIsTrackingAccepted(true); CSQ.optIn(); };
return ( <View> <Text>Please accept our privacy policy to proceed.</Text> <Button title="Accept Policy" onPress={handleAcceptPolicy} /> </View> );};
export default PolicyConsentScreen;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.
Heap.identify("some_identity")CSQ.identify("some_identity")For more information on SDK methods, see the SDK API reference.
GDPR / Identification
| Heap Classic SDK | CSQ SDK |
|---|---|
Heap.identify(identity: String) | CSQ.identify(identity: String) |
Heap.resetIdentity() | CSQ.resetIdentity() |
Heap.getUserId() | CSQ.onMetadataChange(metadata => metadata.userID) |
Heap.getSessionId() | CSQ.onMetadataChange(metadata => metadata.sessionID) |
Heap.getIdentity() | CSQ.onMetadataChange(metadata => metadata.identity) |
Property tracking
| Heap Classic SDK | CSQ SDK |
|---|---|
Heap.addUserProperties(properties: Properties) | CSQ.addUserProperties(properties: Record<string PropertyValue>) |
Heap.addEventProperties(properties: Properties) | CSQ.addEventProperties(properties: Record<string, PropertyValue>) |
Heap.removeEventProperty(name: string) | CSQ.removeEventProperty(name: string) |
Heap.clearEventProperties() | CSQ.clearEventProperties() |
Event tracking
| Heap Classic SDK | CSQ SDK |
|---|---|
Heap.track(event: string, properties?: Properties | null, timestamp?: Date | null, sourceInfo?: SourceInfo | null, pageview?: Pageview | 'none' | null) | CSQ.trackEvent(event: string, properties?: Record<string, PropertyValue>)CSQ.trackScreenview(name: string, cvars?: CustomVar[]) |
Personal Data Handling and Masking
| Heap Classic SDK | CSQ SDK |
|---|---|
\<HeapIgnore> | \<CSQMask> |
\<HeapIgnoreTargetText> | \<CSQMask ignoreTextOnly> |
withHeapIgnore | withCSQMask |
SDK initialization and manipulation
| Heap Classic SDK | CSQ SDK |
|---|---|
Heap.setAppId("YOUR_ENVIRONMENT_ID") | CSQ.configureProductAnalytics("YOUR_ENVIRONMENT_ID") |
Heap.setTrackingEnabled(true) | CSQ.resumeTracking() |
Heap.setTrackingEnabled(false) | CSQ.pauseTracking() |
Checklist
Section titled ChecklistCongratulations! You’re all set. Use this checklist to ensure everything is correctly updated.
Ensure that you are using a version 6.0.0 or later of the Contentsquare React Native SDK.
Your import { Heap } from '@heap/react-native-heap'
import declarations have been updated to import { CSQ } from '@contentsquare/react-native-bridge'.
You no longer have references to Heap. methods in your codebase.
You no longer have references to <HeapIgnore>, <HeapIgnoreTargetText> or withHeapIgnore components in your codebase.
All calls to the CSQ SDK use the CSQ.namespace.