API Reference

Overview

The Nudge Android SDK allows you to integrate the core functionalities provided by Nudge into your Android application. nudge_android_v2 is the required package that you would need to integrate to start using Nudge's capabilities.

Installation

Find the detailed instructions to install the latest version of nudgecorev2:

Add the following to your settings.gradle according to your package setup:

repositories{
   maven{
    url "https://github.com/nudgenow/libraries/raw/main/nudge_android_v2/"
  }
}
maven {
            url = uri("https://github.com/nudgenow/libraries/raw/main/nudges/")
        }

Once done, add the following to your project build.gradle

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

Once added, import the nudgecorev2 package module-wide by adding the following to your app's build.gradle

latest_version:1.0.0

 implementation "com.nudgenow.nudge_android:nudge_android_v2:latest_version"
implementation ("com.nudgenow.nudges:nudges:1.0.2")


Initialise Nudge

If you have your custom Application Class extend your application class to NudgeApplicationClass

import com.nudgenow.nudgecorev2.core.NudgeInitialise

class YourApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        NudgeInitialise(this,
            apiKey = "API_KEY",
           )
    }
}
import com.nudgenow.nudgecorev2.core.NudgeInitialise

class YourApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        NudgeInitialise(this,
            apiKey = "API_KEY",
           )
    }
}



Usage

Identify Users

  • After adding the Nudge package to your project's dependencies in the build.gradle file. This will download the - package and its dependencies, allowing you to import and utilize the Nudge package in your code.
				HashMap<String, Object> properties = new HashMap<>();
        properties.put("age", 30);
        properties.put("subscribed", true);

        Nudge.userIdentifier(
            "externalId123",     // externalId (non-nullable)
            "John Doe",          // name (nullable)
            "[email protected]",  // email (nullable)
            "1234567890",        // phoneNumber (nullable)
            properties           // properties (nullable)
        );
// Call userIdentifier method
    val properties = hashMapOf<String, Any>(
        "age" to 30,
        "subscribed" to true
    )

    Nudge.userIdentifier(
        externalId = "externalId123",  // externalId (non-nullable)
        name = "John Doe",             // name (nullable)
        email = "[email protected]", // email (nullable)
        phoneNumber = "1234567890",    // phoneNumber (nullable)
        properties = properties        // properties (nullable)
    )

Step 2: Track Event

  • Event Tracking
  HashMap<String, Object> trackProperties = new HashMap<>();
        trackProperties.put("level", 5);
        trackProperties.put("score", 1000);

        Nudge.track(
            "LevelComplete",     // event name
            trackProperties      // event properties (nullable)
        );
 val trackProperties = hashMapOf<String, Any>(
        "level" to 5,
        "score" to 1000
    )

    Nudge.track(
        event = "LevelComplete",    // event name
        properties = trackProperties // event properties (nullable)
    )

UserSignout


 Nudge.userSignout()
 Nudge.userSignout()

Capturing Screenshot

Add the following in your Manifest file. The below snippet will enable Nudge to capture app screens so that you can see them in your dashboard. You will get SCHEME_ID from dashboard

   <activity
        android:name="com.nudgenow.nudgecorev2.core.NudgePairActivity"
        android:exported="true"
        android:launchMode="singleInstance">
        <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="nudge-{SCHEME_ID}"
            android:host="nudgenow.com"
            android:pathPattern="/.*/.*" />
        </intent-filter>
    </activity>

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="{YOUR_APP_NAME}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>
  

Replace {YOUR_APP_NAME} with your package name. Example : com.example.appname

That's it!

Check out the WHAT'S NEXT Section Below to integrate experiences