Initialize LogRocket and start recording sessions
Call init() with your appID to configure and start LogRocket. You can find your appID on https://app.logrocket.com under Settings > Project Setup.
Adding the SDK
Our React Native package is available on NPM. New releases of the LogRocket Native SDKs are catalogued on our Mobile SDK Changelog.
npm install --save @logrocket/react-nativeWhen installing the LogRocket React Native package in a project you may see warnings about there being unmet peer dependencies due to the
expoand/orexpo-build-propertiespackages not being provided. These warnings can be disregarded if Expo isn't being used for this project.
Preparing Android
In order for our Android Native SDK to be added to the application a small change must be made to the android/build.gradle file: find the repositories block under and add our maven repository. This must be added in the repositories section under allprojects and NOT in the buildscript section.
allprojects {
repositories {
// Add this declaration to any existing repositories block. Do not remove any existing entries in the block.
maven { url "https://storage.googleapis.com/logrocket-maven/" }
}
}Preparing iOS
Our iOS Native SDK must be added to the iOS project to record sessions. It can be installed from Swift Package Manager or CocoaPods.
Swift Package Manager
There are two ways to use Swift Package Manager, depending on whether your project still uses CocoaPods.
Without CocoaPods (React Native 0.87+)
React Native 0.87 adds Swift Package Manager support that replaces CocoaPods entirely. As of version 3.14.0, the LogRocket React Native SDK ships its own Package.swift, so React Native links it automatically with no additional LogRocket configuration. This setup requires iOS 15.0 or greater.
To set up your project for Swift Package Manager, follow React Native's setup instructions.
With CocoaPods (React Native 0.75+)
Your React Native project can install the LogRocket native iOS SDK via Swift Package Manager while continuing to use CocoaPods for everything else. Set the LOGROCKET_USE_SPM environment variable when executing pod install. As a prerequisite, your build must also run with dynamic linking enabled in your Podfile: use_frameworks! :linkage => :dynamic.
USE_FRAMEWORKS=dynamic LOGROCKET_USE_SPM=1 pod installCocoaPods
This is the default installation method. First update your Podfile to use the correct iOS version with platform :ios, '12.0' (or greater) and then run the following:
npx pod-installInitializing the SDK
Initializing the SDK is as simple as importing the package and running the initialization method. A good place to initialize the SDK is in a useEffect hook in your top-level Application component.
Replace <APP_SLUG> with your LogRocket application slug, located in our dashboard's quick start guides.
import React, { useEffect } from 'react';
import LogRocket from '@logrocket/react-native';
const App = () => {
useEffect(() => {
LogRocket.init('<APP_SLUG>');
}, []);
// Your application entry
};
React Native New ArchitectureThe LogRocket React Native SDK supports React Native's New Architecture (the default as of React Native 0.76) as of version 1.46.4. For apps that use the LogRocket React Native SDK's view redaction features and are transitioning to the New Architecture, we recommend reviewing the redaction documentation for important changes that may be necessary as part of your transition.

