Android

Overview

Iteratively supports tracking analytics events from Android apps (API 22 and above) written in Kotlin and Java.

In Kotlin and Java, the tracking library exposes a type-safe function for every event in your team’s tracking plan. The function’s arguments correspond to the event’s properties and are strongly typed to allow for code completion and compile-time checks.

Installation

Generate the SDK

If you have not yet installed the Itly CLI, install it now.

To generate the Itly SDK, run itly init and itly pull {source} in the top-most folder of your project. By default, the SDK will be generated in ./app/src/main/java/io/itly/.

Tip

{source} is the name of the source you created in your tracking plan (e.g. android).

Install dependencies

To validate your analytics events, the Android SDK depends on everit-org/json-schema (Apache License 2.0). To install this dependency with Gradle:

  • Edit the project-level build.gradle file and add the following to allprojects.repositories (the JSON Schema validation package from Everit is published to JitPack):
maven { url 'https://jitpack.io/' }
  • Edit the app-level build.gradle file and add the following to dependencies:
implementation 'com.github.everit-org.json-schema:org.everit.json.schema:1.12.0'

If you've configured Itly with Amplitude, Segment, or Mixpanel, you'll also install each configured provider's SDK. Edit the app-level build.gradle file and add the following to dependencies:

implementation 'com.amplitude:android-sdk:2.14.1'
implementation 'com.mixpanel.android:mixpanel-android:5.+'
implementation 'com.segment.analytics.android:analytics:4.+'

Import into your app

To use the library, you'll need to import it first:

import io.itly.*;

API

Load

Load the Itly SDK once when your application starts. The load() (init() in Java) method accepts an options object that lets you configure how the Itly SDK works:

OptionsDescription
contextAn object with a set of properties to add to every event sent by the Itly SDK.

Only available if there is at least one source template associated with your your team's tracking plan.
disabledSpecifies whether the Itly SDK does any work. When true, all calls to the Itly SDK will be no-ops. Useful in local or development environments.

Optional. Defaults to false.
environmentSpecifies the environment the Itly SDK is running in: either production or development. Environment determines which Access Token is used to load the underlying analytics provider libraries.

The option also determines safe defaults for handling event validation errors. In production, when the SDK detects an invalid event, it will log an error but still let the event through. In development, the SDK will throw an exception to alert you that something is wrong.

Optional. Defaults to development.
destinationsSpecifies any analytics provider-specific configuration. The Itly SDK passes these objects in when loading the underlying analytics provider libraries.

Optional.
loggerTo log Itly's logs to a custom logger, implement the ItlyLogger protocol and set logger to an instance of your class. The Itly SDK will call into your class with all debug, info, warn, and error-level messages.

Click here to see an example written in Kotlin.

Click here to see an example written in Java.

Optional. Defaults to standard out.

For example:

Itly.load(
Options(
Context(version = "1.0"),
DestinationsOptions(
CustomOptions(MyCustomDestination())
)
)
);

Track

To track an event, call the event’s corresponding function. Every event in your tracking plan gets its own function in the Itly SDK.

For example, in the code snippet below, our tracking plan contains an event called Activity Created. The event was defined with one required property called title. The property's type is an enum.

Itly.activityCreated(
title = ActivityCreated.Title.MAINACTIVITY
)