Find the Quick Start Guide in our GitHub repo.
We host the library on JitPack.io, so
add the following to the root build.gradle:
groovyCopy123456allprojects {repositories {...maven { url 'https://jitpack.io' }}}
and in your module build.gradle:
groovyCopy1234dependencies {debugImplementation 'com.github.avohq.android-avo-inspector:dev:TAG' // Includes the visual inspector, a tool useful to monitor your analytics calls when developingreleaseImplementation '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.
JavaCopy12import app.avo.inspector.AvoInspector;import app.avo.inspector.AvoInspectorEnv;
KotlinCopy12import app.avo.inspector.AvoInspectorimport app.avo.inspector.AvoInspectorEnv
Obtain the API key in Inspector tab in your Avo.app workspace.
You will need to create an instance of AvoInspector
with the constructor.
JavaCopy1public AvoInspector(String apiKey, Application application, AvoInspectorEnv env, @Nullable Activity rootActivityForVisualInspector)
KotlinCopy1class AvoInspector(apiKey: String?, application: Application?, env: AvoInspectorEnv?, rootActivityForVisualInspector: Activity?)
More about the Visual Inspector belowParameters:
String apiKey
- the API key you get in Inspector tab of your Avo workspaceApplication application
- reference to your Application classAvoInspectorEnv env
- current environment: development, staging or productionActivity rootActivityForVisualInspector
- you root activity that will be used to show Visual Inspector, a view where you can track the reported schemas.
This is the core of the Avo Inspector SDK.
Call **one of the methods** in this section every time an event is tracked.
JavaCopy123@NonNull Map<String, AvoEventSchemaType> trackSchemaFromEvent(@NonNull String eventName, @Nullable JSONObject eventProperties);// or@NonNull Map<String, AvoEventSchemaType> trackSchemaFromEvent(@NonNull String eventName, @Nullable Map<String, ?> eventProperties);
KotlinCopy123fun trackSchemaFromEvent(eventName: String, eventProperties: JSONObject?): Map<String, AvoEventSchemaType>// orfun 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:
JavaCopy1234JSONObject eventProperties = new JSONObject();eventProperties.put("userId", 1337);eventProperties.put("emailAddress", "jane.doe@avo.app");eventProperties.put("key", "value");KotlinCopy123456val 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:JavaCopy1234Map<String, AvoEventSchemaType> eventSchema = new HashMap<>();eventSchema.put("userId", new AvoEventSchemaType.AvoInt());eventSchema.put("emailAddress", new AvoEventSchemaType.AvoString());eventSchema.put("key", newAvoEventSchemaType.AvoString());KotlinCopy12345val eventSchema = mutableMapOf<String, AvoEventSchemaType>().apply {put("userId", AvoInt())put("'emailAddress'", AvoString())put("'key'", AvoString())}
JavaCopy1void trackSchema(@NonNull String eventName, @Nullable Map<String, AvoEventSchemaType> eventSchema);
KotlinCopy1void 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:
JavaCopy1234Map<String, AvoEventSchemaType> eventSchema = new HashMap<>();eventSchema.put("userId", new AvoEventSchemaType.AvoInt());eventSchema.put("emailAddress", new AvoEventSchemaType.AvoString());eventSchema.put("key", new AvoEventSchemaType.AvoString());KotlinCopy12345val 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.
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:
JavaCopy1234Map<String, AvoEventSchemaType> eventSchema = new HashMap<>();eventSchema.put("userId", new AvoEventSchemaType.AvoInt());eventSchema.put("emailAddress", new AvoEventSchemaType.AvoString());eventSchema.put("key", newAvoEventSchemaType.AvoString());KotlinCopy123456val eventSchema = mutableMapOf<String, AvoEventSchemaType>().apply {put("userId", AvoInt())put("'emailAddress'", AvoString())put("'key'", AvoString())}
JavaCopy1static void enableLogging(boolean enable); // static method on AvoInspector
KotlinCopy1fun 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.
JavaCopy1static public void setBatchSize(int newBatchSize) // static method on AvoInspector
KotlinCopy1fun 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.
JavaCopy1static public void setBatchFlushSeconds(int newBatchFlushSeconds) // static method on AvoInspector
KotlinCopy1fun 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.
Visual inspector is actually our Mobile Debugger integrated in Avo Inspector SDK.
Visual Inspector is enabled in development and staging environments by default.
JavaCopy1void showVisualInspector(Activity rootActivity, DebuggerMode visualInspectorMode);
KotlinCopy1fun showVisualInspector(rootActivity: Activity, visualInspectorMode: DebuggerMode)
JavaCopy1void hideVisualInspector(Activity rootActivity);
KotlinCopy1fun hideVisualInspector(rootActivity: Activity)
DebuggerManager
JavaCopy1@Nullable Object getVisualInspector();
KotlinCopy1fun 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.
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.
JavaCopy123456789101112131415Middleware avoInspectorMiddleware = new Middleware() {@Overridepublic 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();
KotlinCopy123456789101112val avoInspectorMiddleware = Middleware { chain ->val payload = chain.payload()if (payload.type() == BasePayload.Type.track) {val trackPayload = payload as TrackPayloadavoInspector.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 for more information.