React Native ConvertedIn SDK
The `react-native-converted-in-sdk` package provides a React Native bridge for integrating the ConvertedIn tracking and analytics SDKs into both iOS and Android applications. It simplifies the process of incorporating e-commerce event tracking, such as 'view content', 'add to cart', 'initiate checkout', and 'purchase', as well as user identification features. The current stable version is 1.1.0, with a recent history of rapid releases (September 2024) addressing bug fixes and minor feature enhancements, indicating active development. A key differentiator is its dual API approach, offering both a functional `initializeSDK` method and a `RNConvertInSDKProvider` component with a `useConvertedInSdk` hook for flexible integration patterns. The library ships with TypeScript type definitions, improving developer experience. ConvertedIn itself is a marketing operating system for e-commerce, focusing on personalized multi-channel marketing to boost customer engagement and ROI.
Common errors
-
Invariant Violation: 'main' has not been registered. This can happen if:
cause This error often indicates an issue with the React Native app's entry point, or a native module crash preventing the JavaScript bundle from loading correctly.fixGiven past issues, ensure you are on `v1.0.2` or newer, and all native linking steps for both iOS (Podfile) and Android (Gradle) are correctly applied, and run `pod install` (iOS) and `./gradlew sync` (Android). -
TypeError: null is not an object (evaluating 'RNConvertedinSdk.initializeSDK')
cause This means the native module `RNConvertedinSdk` was not properly linked or initialized by React Native's bridge, common on iOS if `pod install` was skipped or failed.fixVerify that `pod install` was run in your `ios/` directory, and that the `react-native-converted-in-sdk` entry is correctly present in your `Podfile`. Clean your Xcode build folder and rebuild. -
Could not find com.github.convertedin:android-pixel-sdk:latest. Required by: project :app > project :react-native-converted-in-sdk
cause This Android build error suggests a failure to resolve the underlying native Android SDK dependency, likely due to incorrect Gradle setup or repository access issues.fixEnsure your `android/settings.gradle` and `android/app/build.gradle` files contain the correct `include` and `implementation` lines as per the installation instructions, and sync your Gradle project (`./gradlew sync`). Also ensure you have `mavenCentral()` or `google()` repositories configured in your `build.gradle` files. -
Property 'identifyUser' does not exist on type 'typeof import("react-native-converted-in-sdk")'cause This TypeScript error indicates that the TypeScript compiler cannot find the `identifyUser` method (or similar) in the imported module, often due to missing or outdated type definitions.fixUpgrade to `react-native-converted-in-sdk@1.0.2` or later to get proper type definitions. If already on a recent version, ensure your `tsconfig.json` is correctly configured and your `node_modules` are clean (`rm -rf node_modules && yarn install`).
Warnings
- breaking Versions prior to `v1.0.1` had known issues causing crashes on iOS. It is strongly recommended to use `v1.0.1` or newer for stable iOS compatibility.
- breaking Versions prior to `v1.0.2` had known issues causing crashes on Android, often related to missing native packages or incorrect configuration. Update to `v1.0.2` or later for Android stability.
- gotcha This library requires manual linking steps for both iOS and Android native projects, even with auto-linking in React Native. Ensure you add the Podfile entry for iOS and Gradle configurations for Android as specified in the installation guide.
- gotcha Prior to `v1.0.2`, the package lacked proper TypeScript type definitions, leading to potential type errors and a diminished developer experience when using TypeScript. Developers using older versions will miss type inference and autocompletion.
- gotcha Any SDK method call before initialization (either via `initializeSDK` or the `RNConvertInSDKProvider`) will throw an error with the message: "SDK must be initialized before calling this method".
Install
-
npm install react-native-converted-in-sdk -
yarn add react-native-converted-in-sdk -
pnpm add react-native-converted-in-sdk
Imports
- initializeSDK
const initializeSDK = require('react-native-converted-in-sdk').initializeSDK;import { initializeSDK } from 'react-native-converted-in-sdk'; - RNConvertInSDKProvider
import RNConvertInSDKProvider from 'react-native-converted-in-sdk';
import { RNConvertInSDKProvider } from 'react-native-converted-in-sdk'; - useConvertedInSdk
import { useConvertedInSdk } from 'react-native-converted-in-sdk'; - identifyUser
import { identifyUser } from 'react-native-converted-in-sdk';
Quickstart
import React, { useEffect } from 'react';
import { SafeAreaView, Text, Button, Alert } from 'react-native';
import { RNConvertInSDKProvider, useConvertedInSdk } from 'react-native-converted-in-sdk';
const AppContent = () => {
const { initializeSDK, identifyUser, trackEvent, isInitialized } = useConvertedInSdk();
useEffect(() => {
if (!isInitialized) {
// This is a redundant call if using RNConvertInSDKProvider, but shows manual initialization if not wrapped
initializeSDK({
pixelId: process.env.CONVERTEDIN_PIXEL_ID ?? 'CI-YOUR_PIXEL_ID',
storeUrl: process.env.CONVERTEDIN_STORE_URL ?? 'https://your-store.com',
});
}
console.log('SDK Initialized:', isInitialized);
}, [initializeSDK, isInitialized]);
const handleIdentifyUser = () => {
identifyUser("user@example.com", "+1", "5551234567");
Alert.alert("User Identified", "Check console for details.");
};
const handleTrackPurchase = () => {
trackEvent(
'Purchase',
{
currency: 'USD',
total: 99.99,
products: [
{ id: 'SKU123', quantity: 1, name: 'Sample Product' },
],
}
);
Alert.alert("Event Tracked", "Purchase event sent.");
};
return (
<SafeAreaView style={{ flex: 1, justifyContent: 'center', alignItems: 'center', gap: 20 }}>
<Text style={{ fontSize: 20, fontWeight: 'bold' }}>ConvertedIn SDK Demo</Text>
<Button title="Identify User" onPress={handleIdentifyUser} />
<Button title="Track Purchase Event" onPress={handleTrackPurchase} />
<Text style={{ marginTop: 20 }}>SDK Initialized: {isInitialized ? 'Yes' : 'No'}</Text>
</SafeAreaView>
);
};
export default function App() {
return (
<RNConvertInSDKProvider
pixelId={process.env.CONVERTEDIN_PIXEL_ID ?? 'CI-YOUR_PIXEL_ID'}
storeUrl={process.env.CONVERTEDIN_STORE_URL ?? 'https://your-store.com'}
>
<AppContent />
</RNConvertInSDKProvider>
);
}