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

Heap Classic 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.

Replace the Heap Classic SDK dependency by the CSQ SDK.

Terminal window
yarn remove @heap/react-native-heap
yarn add @contentsquare/react-native-bridge
cd ios && pod install

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

Follow these steps to start the CSQ SDK with your current configuration.

  1. Migrate your app ID and the config options from Heap.setAppId() to CSQ.configureProductAnalytics().

    App.tsx
    import { CSQ } from "@contentsquare/react-native-bridge";
    useEffect(() => {
    Heap.setAppId("YOUR_ENVIRONMENT_ID");
    CSQ.configureProductAnalytics(
    "YOUR_ENVIRONMENT_ID"
    )
    }, []);
  2. For React Native Autocapture, replace the babel plugin from @heap/react-native-heap to @contentsquare/react-native-bridge/babel in 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'],
    };
  3. Remove Heap from app.json plugins array

    app.json
    {
    "plugins": [
    "@heap/react-native-heap"
    ]
    }
  4. Remove Heap.withReactNavigationAutotrack() from navigation

    JavaScript
    import Heap from '@heap/react-native-heap';
    const HeapNavigationContainer = Heap.withReactNavigationAutotrack(
    NavigationContainer
    );
  5. To start Autocapture set enableRNAutocapture = true option:

    App.tsx
    import { CSQ } from "@contentsquare/react-native-bridge";
    useEffect(() => {
    CSQ.configureProductAnalytics(
    "YOUR_ENVIRONMENT_ID",
    {
    enableRNAutocapture: true
    }
    )
    }, []);
  6. 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();
    }, []);

The 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;

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.identify("some_identity")
CSQ.identify("some_identity")

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

GDPR / Identification

Heap Classic SDKCSQ 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 SDKCSQ 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 SDKCSQ 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 SDKCSQ SDK
\<HeapIgnore>\<CSQMask>
\<HeapIgnoreTargetText>\<CSQMask ignoreTextOnly>
withHeapIgnorewithCSQMask

SDK initialization and manipulation

Heap Classic SDKCSQ SDK
Heap.setAppId("YOUR_ENVIRONMENT_ID")CSQ.configureProductAnalytics("YOUR_ENVIRONMENT_ID")
Heap.setTrackingEnabled(true)CSQ.resumeTracking()
Heap.setTrackingEnabled(false)CSQ.pauseTracking()

Congratulations! 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.