Installation
This document will guide you through the installation of the Nudge SDK in your React Native application
1. Installing the package
Run the below command to install the SDK
npm i nudge_react_native_v2
Find the latest version of the package here
Latest Version:
2. Android-Specific Configuration
1. Updating build.gradle
allprojects {
repositories {
maven {
url "https://github.com/nudgenow/android/raw/prod_main/release/"
}
google()
mavenCentral()
}
}
2. Initializing SDK in YourApplication
Navigate to android/app/src/main/kotlin/com/example/example_app/YourApplication.kt
file with the following implementation:
import com.nudgecorev2reactnative.Nudgecorev2ReactNativeModule
import android.app.Application
class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
Nudgecorev2ReactNativeModule.NudgeReactNativeLifecycleCapture(this)
}
}
If you want to initialize the Nudge SDK from android side in your react native application use the below snippet :
import com.nudgecorev2reactnative.Nudgecorev2ReactNativeModule
class YourApplication: Application() {
override fun onCreate() {
super.onCreate()
Nudgecorev2ReactNativeModule.NudgeReactNative.initialise(this, "YOUR_API_KEY", debugMode : Boolean)
}
}
3. Importing the package
To use the Nudge SDK, you need to import the Nudge class in the main entry point of your application.
import { Nudge,Region } from "nudge_react_native_v2";
4. Initialization
Initialize Nudge at the root of your application using the Nudge.init method. This method takes two parameters:
Your public API key (string)
Debug mode (boolean): When true, it will initialize the SDK in debug mode, helping you check logs and debug errors.
const YourApp = () => {
const navigationRef = React.useRef(null);
useEffect(() => {
Nudge.init(
"<YOUR_PUBLIC_API_KEY>",
true, //Debug mode
Region.IN // or Region.US,
navigationRef , // Pass your ref if you are already using one
)
}, [])
return (
//Your Application code
)
}