Reference
Avo Inspector SDKs
Android

Avo Inspector Android SDK

Quick Start Guide

Find the Quick Start Guide in our GitHub repo (opens in a new tab).

Installation

We host the library on JitPack.io, so

add the following to the root build.gradle:

allprojects {
    repositories {
      ...
      maven { url 'https://jitpack.io' }
    }
}

and in your module build.gradle:

dependencies {
    debugImplementation 'com.github.avohq.android-avo-inspector:dev:TAG' // Includes the visual inspector, a tool useful to monitor your analytics calls when developing
    releaseImplementation 'com.github.avohq.android-avo-inspector:prod:TAG' // Does not include the visual inspector
}

Use the latest GitHub release tag to get the latest version of the library.

ProGuard

If you are using ProGuard add the following line to your proguard rules file:

-keep class app.avo.** { *; }

Import

import app.avo.inspector.AvoInspector;
import app.avo.inspector.AvoInspectorEnv;
import app.avo.inspector.AvoInspector
import app.avo.inspector.AvoInspectorEnv

Initialization

Obtain the API key in Inspector tab in your Avo.app (opens in a new tab) workspace.

You will need to create an instance of AvoInspector with the constructor.

public AvoInspector(String apiKey, Application application, AvoInspectorEnv env, @Nullable Activity rootActivityForVisualInspector)
class AvoInspector(apiKey: String?, application: Application?, env: AvoInspectorEnv?, rootActivityForVisualInspector: Activity?)

Parameters:

  • String apiKey - the API key you get in Inspector tab of your Avo workspace
  • Application application - reference to your Application class
  • AvoInspectorEnv env - current environment: development, staging or production
  • Activity rootActivityForVisualInspector - you root activity that will be used to show Visual Inspector, a view where you can track the reported schemas.

More about the Visual Inspector below

Sending event schemas to Avo Inspector

This is the core of the Avo Inspector SDK.

Call **one of the methods** in this section every time an event is tracked.

Option 1

@NonNull Map<String, AvoEventSchemaType> trackSchemaFromEvent(@NonNull String eventName, @Nullable JSONObject eventProperties);
// or
@NonNull Map<String, AvoEventSchemaType> trackSchemaFromEvent(@NonNull String eventName, @Nullable Map<String, ?> eventProperties);
fun trackSchemaFromEvent(eventName: String, eventProperties: JSONObject?): Map<String, AvoEventSchemaType>
// or
fun trackSchemaFromEvent(eventName: String, eventProperties: Map<String, *>?): Map<String, AvoEventSchemaType>

Extracts event schema from event properties represented by the second parameter (JSONObject or Map<String, ?>) and sends the schema to Avo for analysis.

Parameters:

  • String eventName - event name, sometimes referred as event type.
  • @Nullable JSONObject eventProperties or @Nullable Map<String, ?> eventProperties - actual event properties, which will be converted to event schema on the device and the event schema will be sent to Avo. Resulting keys will be JSON fields keys and resulting values will be JSON fields values types converted to schema types.
Example format:
JSONObject eventProperties = new JSONObject();
eventProperties.put("userId", 1337);
eventProperties.put("emailAddress", "jane.doe@avo.app");
eventProperties.put("key", "value");
val eventProperties = JSONObject().apply {
  put("userId", 1337)
  put("emailAddress", "jane.doe@avo.app")
  put("key", "value")
}
 

Return Type:

  • @NonNull Map<String, AvoEventSchemaType> containing event schema, so you can verify that conversion was correct. Example format:
Map<String, AvoEventSchemaType> eventSchema = new HashMap<>();
eventSchema.put("userId", new AvoEventSchemaType.AvoInt());
eventSchema.put("emailAddress", new AvoEventSchemaType.AvoString());
eventSchema.put("key", newAvoEventSchemaType.AvoString());
val eventSchema = mutableMapOf<String, AvoEventSchemaType>().apply {
  put("userId", AvoInt())
  put("'emailAddress'", AvoString())
  put("'key'", AvoString())
}

Option 2

void trackSchema(@NonNull String eventName, @Nullable Map<String, AvoEventSchemaType> eventSchema);
void trackSchema(@NonNull String eventName, @Nullable Map<String, AvoEventSchemaType> eventSchema);

This method allows you to process the event schema before sending it. It's handy to extract the schema from your event properties with extractSchema(Object eventProperties) (see below), process it and then provide it to this method.

Parameters:

  • @NonNull String eventName - event name, also known as event type.
  • @Nullable Map<String, AvoEventSchemaType> eventSchema - actual event schema that will be sent to Avo.
Example format:
Map<String, AvoEventSchemaType> eventSchema = new HashMap<>();
eventSchema.put("userId", new AvoEventSchemaType.AvoInt());
eventSchema.put("emailAddress", new AvoEventSchemaType.AvoString());
eventSchema.put("key", new AvoEventSchemaType.AvoString());
val eventSchema = mutableMapOf<String, AvoEventSchemaType>().apply {
   put("userId", AvoInt())
   put("emailAddress", AvoString())
   put("key", AvoString())
}

See this for details about event schema structure and schema types.

Other methods

1. Extract schema from event properties

java @NonNull Map<String, AvoEventSchemaType> extractSchema(@Nullable Object eventProperties);`kotlin
fun extractSchema(eventProperties: Any?): Map<String, AvoEventSchemaType>

This is the method used by trackSchemaFromEvent internally. Extracts event schema in form of Map<String, AvoEventSchemaType> from an event properties object.

Parameters:

  • @Nullable Object eventProperties - event properties object. If it is an instance of JSONObject or Map<?, ?> it will be processed based on the containing key-value pairs, otherwise the event schema will be based on object fields.

Return Type:

  • @NonNull Map<String, AvoEventSchemaType> containing event schema of the given event properties. Keys are event properties names and values are event properties types.
Example format:
Map<String, AvoEventSchemaType> eventSchema = new HashMap<>();
eventSchema.put("userId", new AvoEventSchemaType.AvoInt());
eventSchema.put("emailAddress", new AvoEventSchemaType.AvoString());
eventSchema.put("key", newAvoEventSchemaType.AvoString());
val eventSchema = mutableMapOf<String, AvoEventSchemaType>().apply {
   put("userId", AvoInt())
   put("'emailAddress'", AvoString())
   put("'key'", AvoString())
}
 

2. Print logs

static void enableLogging(boolean enable); // static method on AvoInspector
fun enableLogging(enable: Boolean) // static method on AvoInspector

enableLogging controls printing of tracked event schemas and other helpful information to logcat. Enabled by default in development environments.

Parameters:

  • boolean enable - sets whether Avo Inspector SDK will print logs to the logcat.

3. Control batching size

static public void setBatchSize(int newBatchSize) // static method on AvoInspector
fun setBatchSize(newBatchSize: Int) // static method on AvoInspector

Enables manual control over events batching. Default batch size in production is 30, i.e. the library attempts to send event schemas to the server when it has 30 or more schemas. In development batching is disabled by default.

Parameters:

  • int newBatchSize - sets batch size.

4. Control batching interval

static public void setBatchFlushSeconds(int newBatchFlushSeconds) // static method on AvoInspector
fun setBatchFlushSeconds(newBatchFlushSeconds: Int) // static method on AvoInspector

Enables manual control over events batching. Default production batch flush interval is 30 seconds, i.e. the library attempts to send event schemas to the server when 30 or more seconds pass, given there are unsent schemas.

Parameters:

  • int newBatchFlushSeconds - sets batch flush time in seconds.

Using the Visual Inspector

Visual inspector is actually our Mobile Debugger integrated in Avo Inspector SDK.

Visual Inspector is enabled in development and staging environments by default.

Show

void showVisualInspector(Activity rootActivity, DebuggerMode visualInspectorMode);
fun showVisualInspector(rootActivity: Activity, visualInspectorMode: DebuggerMode)

Hide

void hideVisualInspector(Activity rootActivity);
fun hideVisualInspector(rootActivity: Activity)

Get instance of DebuggerManager

@Nullable Object getVisualInspector();
fun getVisualInspector(): Object?

In the :dev dependency the returned object is a nullable DebuggerManager. In the :prod dependency it always returns null. See more about the DebuggerManager in it's GitHub repo (opens in a new tab).

Auto inspection with Segment SDK

Here is a code snippet you can use to easily integrate with Segment. After registering the middleware schemas of all the events sent to Segment will automatically be sent to Avo, i.e. you don't need to call trackSchemaFromEvent or trackSchema methods.

Middleware avoInspectorMiddleware = new Middleware() {
    @Override
    public void intercept(Chain chain) {
        BasePayload payload = chain.payload();
        if (payload.type() == BasePayload.Type.track) {
            TrackPayload trackPayload = (TrackPayload) payload;
            avoInspector.trackSchemaFromEvent(trackPayload.event(), trackPayload.properties());
        }
        chain.proceed(payload);
    }
};
 
Analytics analytics = new Analytics.Builder(getApplicationContext(), "SEGMENT_ANALYTICS_WRITE_KEY")
    .middleware(avoInspectorMiddleware)
    .build();
val avoInspectorMiddleware = Middleware { chain ->
    val payload = chain.payload()
    if (payload.type() == BasePayload.Type.track) {
        val trackPayload = payload as TrackPayload
        avoInspector.trackSchemaFromEvent(trackPayload.event(), trackPayload.properties())
    }
    chain.proceed(payload)
}
 
val analytics = Analytics.Builder(applicationContext, "SEGMENT_ANALYTICS_WRITE_KEY")
    .middleware(avoInspectorMiddleware)
    .build()

See Segment android middleware docs (opens in a new tab) for more information.