Avo Inspector Java 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:
repositories {
mavenCentral()
...
maven { url 'https://jitpack.io' }
}
and:
dependencies {
debugImplementation 'com.github.avohq.java-avo-inspector:TAG'
}
Use the latest GitHub release tag to get the latest version of the library.
Import
import is.avo.inspector.AvoEventSchemaType;
import is.avo.inspector.AvoInspector;
import is.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(@NotNull String apiKey, @NotNull String appVersion, @NotNull String appName, @NotNull AvoInspectorEnv env)
Parameters:
String apiKey
- the API key you get in Inspector tab of your Avo workspaceString appVersion
- app version to attribute the events toString appName
- application nameAvoInspectorEnv env
- current environment: AvoInspectorEnv.Dev, AvoInspectorEnv.Staging or AvoInspectorEnv.Prod
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);
Example usage:
void trackEvent(@NonNull String eventName, @Nullable Map<String, ?> eventParams) { tracker.track(eventName, eventParams); this.avoInspector.trackSchemaFromEvent(eventName, eventParams); }
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");
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());
Option 2
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());
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 ofJSONObject
orMap<?, ?>
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());
2. Print logs
static void enableLogging(boolean enable); // 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.