rudderlabs / rudder-sdk-android

Android SDK for RudderStack - the Customer Data Platform for Developers.
https://www.rudderstack.com
Other
18 stars 28 forks source link
analytics analytics-platform android android-library android-sdk java kotlin open-source rudder sdk

The Customer Data Platform for Developers

Website · Documentation · Community Slack


RudderStack Android SDK

RudderStack's Android SDK lets you track event data from your Android applications. After integrating the SDK, you will be able to send the event data to your preferred destination/s such as Google Analytics, Amplitude, and more.

For detailed documentation on the Android SDK, click here.

Get started with the Android SDK

  1. Add these lines to your project level build.gradle file:
buildscript {
    repositories {
        mavenCentral()
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}
  1. Then, add the dependency under dependencies as shown:

implementation 'com.rudderstack.android.sdk:core:1.x.x'

Initializing RudderClient

val rudderClient: RudderClient = RudderClient.getInstance(
    this,
    <WRITE_KEY>,
    RudderConfig.Builder()
        .withDataPlaneUrl(<DATA_PLANE_URL>)
        .build()
)

or (compatible with existing Segment code)

RudderClient.Builder builder = new RudderClient.Builder(this, <WRITE_KEY>);
RudderClient.setSingletonInstance(builder.build());

Sending events

rudderClient.track(
    RudderMessageBuilder()
        .setEventName("some_custom_event")
        .setProperty(
            TrackPropertyBuilder()
                .setCategory("test_category")
                .build()
        )
        .setUserId("test_user_id")
)

or (compatible with existing Segment instrumentation code)

String customEvent = "some_custom_event";
String propertyKey = "some_property_key";
String propertyValue = "some_property_value";
RudderClient.with(this).track(
        customEvent,
        new RudderProperty().putValue(propertyKey, propertyValue)
);

For more information on the different types of events supported by the Android SDK, refer to our docs.

Registering your callbacks

For device mode destinations, you can register callbacks, which will be executed after the native SDK has been successfully initialized. Use the onIntegrationReady method to register your callback.

The following snippet shows an example:

rudderClient.onIntegrationReady("Lotame") {
  var nativeSDK  = (it as LotameIntegration)
  // your custom code
}

The variable it contains the intialized nativeSDK object.

The method onIntegrationReady accepts two arguments: the integration name (e.g. "Lotame") and the callback.

Registering Lotame's onSync callback shows one more example of registering a callback using onIntegrationReady.

Contribute

We would love to see you contribute to this project. Get more information on how to contribute here.

About RudderStack

RudderStack is a customer data platform for developers. Our tooling makes it easy to deploy pipelines that collect customer data from every app, website and SaaS platform, then activate it in your warehouse and business tools.

More information on RudderStack can be found here.

Contact us

For more support on using the RudderStack Android SDK, you can contact us or start a conversation on our Slack channel.