Android SDK

1. Adding Anecdote to your project

  • Include jitpack in your root settings.gradle file.

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        ...
        maven {
            url = uri("https://jitpack.io")
        }
    }
}
  • And add it's dependency to your app level build.gradle file.

dependencies {
    implementation 'com.github.Anecdote-AI:anecdote-android:Tag'
}

2. Initialize

In your Application class add this line to your onCreate method.

    Anecdote.init(applicationContext = this, apiKey = API_KEY)

3. Set User Parameters

Add the following lines to set the user id and custom parameters.

    Anecdote.setUserId("123")
    Anecdote.setCustomParameters(hashMapOf("email" to "example@gmail.com"))

Note: User id is a unique identifier for the user, and mandatory to set. And custom parameters are additional information about the user that can be used for targeting the survey.

4. Trigger Event

To trigger an event, add the following line.

    Anecdote.triggerEvent(event = "example_button_click")

Events can be triggered as needed, for example, when a user clicks a button or logs in. Event can be triggered from any part of the app, such as an Activity, ViewModel, etc.

5. Dispose

If needed to cancel already triggered events that are still being processed, add the following line.

    Anecdote.dispose()

For example, if events were triggered on a screen but the survey hasn’t been shown yet, and the screen is closed without needing to show the survey anymore, the dispose method can be called to cancel the processing of the triggered events.

6. Terminate

To disable the SDK add the following line.

    Anecdote.terminate()

Once terminated, all SDK processing will stop, and further calls (like triggerEvent) will not have any effect. For example, terminate method can be called when the user logs out of the app.

Last updated