react-native-inhouse-sdk
v1.0.9
Published
A React Native module for tracking SDK functionality
Maintainers
Readme
React Native Inhouse Tracking SDK
A React Native module for tracking SDK functionality with install referrer support.
Installation
Using npm
npm install react-native-inhouse-sdkUsing yarn
yarn add react-native-inhouse-sdkiOS Installation
The SDK uses CocoaPods for iOS. After installation, run:
cd ios && pod installAndroid Installation
The SDK will be automatically linked via React Native's autolinking feature.
AndroidManifest.xml Configuration
Add the following receiver to your android/app/src/main/AndroidManifest.xml inside the <application> tag:
<receiver
android:name="co.tryinhouse.android.InstallReferrerReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>This receiver is required for install referrer tracking functionality.
Intent Filters for Deep Linking
Add the following intent filters to your main activity inside the <activity> tag in android/app/src/main/AndroidManifest.xml:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="myandroidapp"/>
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Do not include other schemes. -->
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="your-shortlink-domain.tryinhouse.co" />
</intent-filter>These intent filters enable deep linking functionality for your app. The first filter handles custom scheme URLs (e.g., myandroidapp://), while the second filter handles HTTP/HTTPS URLs with your TryInHouse domain for App Links verification.
Manual Linking (if needed)
- Add the following to your
android/settings.gradle:
include ':react-native-inhouse-sdk'
project(':react-native-inhouse-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-inhouse-sdk/android')- Add the following to your
android/app/build.gradle:
dependencies {
implementation project(':react-native-inhouse-sdk')
}- Add the following to your
MainApplication.java:
import co.tryinhouse.react_native.TrackingSDKPackage;
// In the getPackages() method:
packages.add(new TrackingSDKPackage());Usage
Basic Setup
import TrackingSDK from "react-native-inhouse-sdk";
// Initialize the SDK
await TrackingSDK.initialize(
"your-project-id",
"your-project-token",
"your-shortlink-domain",
"https://api.tryinhouse.co", // optional
true // enable debug logging
);Track Events
// Track app open
const result = await TrackingSDK.trackAppOpen("shortlink-url");
// Track session start
const sessionResult = await TrackingSDK.trackSessionStart("shortlink-url");
// Track short link click
const clickResult = await TrackingSDK.trackShortLinkClick(
"shortlink-url",
"deeplink-url"
);Install Referrer
// Get install referrer storred in shared preferences
const referrer = await TrackingSDK.getInstallReferrer();
// Fetch install referrer (async)
const fetchedReferrer = await TrackingSDK.fetchInstallReferrer();Event Listeners
// Add callback listener
const subscription = TrackingSDK.addCallbackListener((data) => {
console.log("SDK Callback:", data.callbackType, data.data);
});
// Remove listener
TrackingSDK.removeCallbackListener(subscription);
// Remove all listeners
TrackingSDK.removeAllListeners();The SDK tracks the following events, all of which send link data:
session_start_shortlink: Triggered when a session starts with a shortlinkapp_open_shortlink: Triggered when the app opens via a shortlinkapp_install_from_shortlink: Triggered when the app is installed from a shortlink
All events include link data with the following structure:
{
"id": "string",
"domain": "string",
"key": "string",
"url": "string",
"short_link": "string",
"title": "string",
"description": "string",
"image": "string",
"utm_source": "string",
"utm_medium": "string",
"utm_campaign": "string",
"utm_term": "string",
"utm_content": "string",
"ios": "string",
"android": "string",
"project_id": "string",
"folder_id": "string",
"playstore": "string",
"appstore": "string",
"deeplink_path": "string",
"link_data": "string", // json object with custom key value pairs
"website_link": "string",
"refer_code": "string",
"unique_clicks": 0,
"app_installs": 0
}App Lifecycle
// Call when app resumes
await TrackingSDK.onAppResume();
// Reset first install state (for testing)
await TrackingSDK.resetFirstInstall();Configuration
The SDK automatically uses the React Native and other dependencies from your project. You can configure specific versions in your project's android/build.gradle:
ext {
// SDK will use these versions if available
okhttpVersion = '4.12.0'
gsonVersion = '2.10.1'
installReferrerVersion = '2.2'
coroutinesVersion = '1.7.3'
coreKtxVersion = '1.12.0'
appcompatVersion = '1.6.1'
}API Reference
Methods
initialize(projectId, projectToken, shortLinkDomain, serverUrl?, enableDebugLogging?): Initialize the SDKonAppResume(): Call when app resumestrackAppOpen(shortLink?): Track app open eventtrackSessionStart(shortLink?): Track session starttrackShortLinkClick(shortLink, deepLink?): Track short link clickgetInstallReferrer(): Get current install referrerfetchInstallReferrer(): Fetch install referrer asynchronouslyresetFirstInstall(): Reset first install stateaddCallbackListener(callback): Add event listenerremoveCallbackListener(subscription): Remove specific listenerremoveAllListeners(): Remove all listeners
Types
TrackingSDKCallback: Callback data structureTrackingSDKInterface: Main SDK interface
Troubleshooting
Common Issues
- Build errors: Make sure you have the latest React Native version
- Linking issues: The SDK uses autolinking, but you can manually link if needed
- iOS pod install: Run
cd ios && pod installafter installation
Debug Mode
Enable debug logging during initialization to see detailed logs:
await TrackingSDK.initialize(
"project-id",
"project-token",
"shortlink-domain",
"https://api.tryinhouse.co",
true // enable debug logging
);License
MIT
