Skip to main content

Basic Integration

This will Guide you through the basic integration of Nudge SDK with various platform. This includes installing sdk, tracking events and tracking user.

Installing the SDK

Latest Version:

To install the nudge_android_v2 SDK into your Android application, follow these steps:

1. Configure settings.gradle

Add the following repository to your settings.gradle file to download the Nudge SDK:

dependencyResolutionManagement {
repositories {
maven {
url "https://github.com/nudgenow/android/raw/prod_main/release/"
}
}
}

2. Add Plugin to build.gradle (Project-Level)

Ensure you have the Kotlin Android plugin in your project-level build.gradle:

plugins {
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}

3. Add SDK Dependency to build.gradle (App-Level)

Import the nudge_android_v2 SDK module-wide in your app-level build.gradle:

    dependencies {
implementation "com.nudgenow.nudge_android:nudge_android_v2:latest_version"
}

Sync Gradle: After adding the dependencies, sync your project in Android Studio.

Initialising Nudge

Initialize NudgeCore in onCreate() method of the Application class of your android app.

    import com.nudgenow.nudgecorev2.core.NudgeInitialise

class YourApplication : Application() {

override fun onCreate() {
super.onCreate()
NudgeCore.initialize(
application = this, // Context of Your Application
apiKey = "YOUR API KEY",
debugMode = true // THIS WILL ENABLE Nudge's Log to get printed
)
}
}
warning

Configure Proguard Rules

Add the below rule to your proguard rules

-keep class com.nudgenow.** { *; }

Identifying Users

You can identify users using the userIdentifier method in our SDK. This method requires a unique user identifier and allows you to include additional user properties within a properties object.

info
  • To display the user's name, email, and phone number in the Nudge dashboard, pass these properties separately and do not include them again inside the props object.
  • Keys in properties map should be in smaller case
  • If you are sending any string properties the length should nt exceed 256 Characters
val props = HashMap<String, Any>().apply {
put("sample_string_data", "20") // String
put("sample_float_data", 17.5) // Float
put("sample_int_data", 11) // String (Overwrites previous "zepto" entry)
put("sample_boolean_data", false) // Boolean
}

Nudge.getInstance().userIdentifier(
externalId = "unique_id_for_user",
properties = props, //optional
onResult = object : Nudge.NudgeResponse {
override fun onSuccess(response: String) {
// Handle success
}

override fun onFailure(error: String) {
// Handle failure
}
})

Tracking Events

Nudge provides a track method to track user interactions in your application. You can also send event properties with the track method.

info
  • Event name should be in smaller case.
  • Keys in properties map should be in smaller case
  • If you are sending any string properties the length should n't exceed 256 Characters
val props = HashMap<String, Any>().apply {
put("sample_string_data", "20") // String
put("sample_float_data", 17.5) // Float
put("sample_int_data", 11) // Integer
put("sample_boolean_data", false) // Boolean
}

Nudge.getInstance().track(
"event_name", // Event name
props, // Event properties (optional)
object : Nudge.NudgeResponse {
override fun onSuccess(response: String) {
// Handle success
}

override fun onFailure(error: String) {
// Handle failure
}
}
)

Warning
Event name, event properties, and user properties all follow this regex:^[a-z][a-z0-9_]{2, 99}$
  • Only small alphabets, numbers, and underscores (_) are allowed.
  • Spaces are not allowed in event names.
  • Name cannot start with a number; it needs to start with an alphabet.
  • The name should be between 2 and 99 characters in length.
  • If any capital letter is sent, it will be converted to lowercase.

User Sign Out

Once the user signs out from your application, use the userSignOut method provided by Nudge to clear any cached data for that user.

Nudge.getInstance().userSignOut(
onResult = object : Nudge.NudgeResponse {
override fun onSuccess(response: String) {

}
override fun onFailure(error: String) {

}
})