Android SDK methods

View as Markdown

The Android SDK is equipped to handle all essential event calls, including screen, track, identify, and group. Furthermore, it offers functionalities to efficiently manage session information.

With these capabilities, you can seamlessly track and analyze user interactions, facilitating a comprehensive understanding of user behavior and engagement.

Below the Android SDK methods:

screen

The screen method implements the screen call.

The screen call enables you to capture instances when a user views a screen and record associated properties or details about that particular screen.

Syntax

screen(title: String, properties: JsonObject = emptyJsonObject, category: String = ""): Unit

Parameters

Name Type Required Description
title String
Title of the screen.
properties JsonObject Properties of the screen.
category String Category to describe the screen.

Example

Kotlin

analytics.screen("Order completed", buildJsonObject {
    put("items", 3)
    put("total", 274.99)
})

Java

analytics.screen("Order completed", Builders.buildJsonObject(o -> {
    o.put("items", 3)
      .put("total", 274.99);
}));

track

The track method implements the track call.

The track call is used to send specific events or pipelines, and associated properties, that occur when users interact with your application or website.

Syntax

track(name: String, properties: JsonObject = emptyJsonObject): Unit

Parameters

Name Type Required Description
name String
Name of the event.
properties JsonObject Properties of the event.

Example

Kotlin

analytics.track("Product added to cart", buildJsonObject {
    put("id", 12345)
})

Java

analytics.track("Product added to cart", Builders.buildJsonObject(o -> {
    o.put("id", 12345);
}));

identify

The identify method implements the identify call.

Through an identify call, you can connect previous and upcoming events to a recognized user and save details about them along with their events, such as name and email. The user information can also be utilized to update and enhance unified data from other sources.

Syntax

identify(userId: String, traits: JsonObject = emptyJsonObject): Unit

Parameters

Name Type Required Description
userId String
Identifier of the user.
traits JsonObject Traits to add to the user's traits.

Example

Kotlin

analytics.identify("59a20n37ec82", buildJsonObject {
    put("firstName", "Emily")
    put("lastName", "Johnson")
    put("email", "emma.johnson@example.com")
})

Java

analytics.identify("59a20n37ec82", Builders.buildJsonObject(o -> {
    o.put("firstName", "Emily")
      .put("lastName", "Johnson")
      .put("email", "emma.johnson@example.com");
}));

group

The group method implements the group call.

The group call provides a way to associate individual users with groups, such as a company, organization, team, association, or initiative. A user who has been identified can be associated with several groups.

Syntax

group(groupId: String, traits: JsonObject = emptyJsonObject): Unit

Parameters

Name Type Required Description
groupId String
Identifier of the group.
traits JsonObject Traits of the group.

Example

Kotlin

analytics.group("84s76y49tb28v1jxq", buildJsonObject {
    put("name", "AcmeTech")
    put("industry", "Technology")
    put("employeeCount", 100)
})

Java

analytics.group("84s76y49tb28v1jxq", Builders.buildJsonObject(o -> {
    o.put("name", "AcmeTech")
      .put("industry", "Technology")
      .put("employeeCount", 100);
}));

userId

The userId method is used to get the identifier of the user. It always returns the user's identifier, or null if there is no identifier.

To modify the user's identifier, use the identify method or the reset method.

Syntax

userId(): String?

Parameters

There are no parameters.

Examples

Kotlin

val userId = analytics.userId()

Java

String userId = analytics.userId();

traits

The traits method is used to retrieve a user's traits. These traits are for the anonymous user if the user is anonymous, and for the non-anonymous user if non-anonymous.

To modify the user's traits, use the identify method or the reset method.

Syntax

traits(): jsonObject?

Parameters

There are no parameters.

Examples

Kotlin

val traits = analytics.traits()

Java

JsonObject traits = analytics.traits();

alias

The alias method is used to merge two user identities, effectively connecting two sets of user data as one. This method is applicable when the event is sent to a destination, such as Mixpanel.

In Krenalis, user merging is handled by Krenalis's Identity Resolution. Therefore this method is not utilized in this process.

Syntax

alias(newId: String): Unit

Parameters

Name Type Required Description
newId String
The new ID you want to alias the existing ID to.

Example

Kotlin

analytics.alias("12r60m18ff04")

Java

analytics.alias("12r60m18ff04");

anonymousId

The anonymousId method is used to retrieve the Anonymous ID.

To modify the Anonymous ID, use the identify method or the reset method.

Syntax

anonymousId(): String

Parameters

There are no parameters.

Examples

Kotlin

val anonymousId = analytics.anonymousId()

Java

String anonymousId = analytics.anonymousId();

reset

The reset method resets the user identifier, and updates or removes the Anonymous ID and traits according to the strategy (as detailed in the table below). If all is true it always resets the Anonymous ID by generating a new one, and ends the session if one exists, regardless of the strategy.

Strategy Behavior of reset()
Conversion Removes User ID and user traits, and changes Anonymous ID and session.
Fusion Removes User ID and user traits. Does not change Anonymous ID or session.
Isolation Removes User ID and user traits and changes Anonymous ID and session.
Preservation Removes User ID. Restores Anonymous ID, user traits and session to their state before the latest identify call.

Syntax

reset(all: Boolean = false): Unit

Parameters

Name Type Required Description
all Boolean Indicates if the Anonymous ID and the session must be reset, regardless of the strategy.

Example

Kotlin

analytics.reset()

Java

analytics.reset();

Segment Compatibility

To align with Segment's reset() behavior, choose the "Conversion" or "Isolation" strategy in Krenalis. Note that reset(true) is not available in Segment.

RudderStack Compatibility

To match RudderStack's reset() behavior, choose the "Conversion" or "Isolation" strategy in Krenalis. In Krenalis, reset(true) works the same way as it does in RudderStack for all strategies.

getSessionId

The getSessionId method returns the current session identifier. It returns null if there is no session.

Syntax

getSessionId(): Long?

Parameters

There are no parameters.

Example

Kotlin

val sessionId = analytics.getSessionId()

Java

long sessionId = analytics.getSessionId();

startSession

The startSession method starts a new session using the provided identifier. If the identifier provided is null, it generates one automatically. The provided session Id, if not null, must be a positive Long.

Syntax

startSession(id: Long?): Unit

Parameters

Name Type Required Description
id Long?
Session identifier. Must be positive.

Example

Kotlin

analytics.startSession(123456789L)

Java

analytics.startSession(123456789L);

endSession

The endSession method ends the session.

Syntax

endSession(): Unit

Parameters

There are no parameters.

Example

Kotlin

analytics.endSession()

Java

analytics.endSession();