Skip to content

setgreet/setgreet-android-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Setgreet Android SDK

Maven Central

Setgreet Android SDK allows you to show Setgreet flows in your Android app.

Requirements

  • Android 5.0 (API level 21) and above

Installation

Add mavenCentral() to your project's build.gradle.kts file:

allprojects {
    repositories {
        mavenCentral()
    }
}

Add the following to your app's build.gradle.kts file:

dependencies {
    implementation("com.setgreet:setgreet:LATEST_VERSION")
}

Usage

Initialization

  • Setgreet App Key: You can find your App Key at Apps page.

Initialize the SDK in your Application class or where you want:

class MyApplication : Application() {
    
    override fun onCreate() {
        super.onCreate()

        Setgreet.initialize(
            context = this,
            appKey = "APP_KEY",
            config = SetgreetConfig(
                debugMode = false
            )
        )
    }
}

Identify User

Identifies a user for Setgreet analytics and flow management.

Parameters:

  • userId (String): The unique identifier for the user
  • attributes (Optional): Additional user attributes
  • operation (Optional): The operation type for user attributes (CREATE or UPDATE)
  • locale (Optional): User's locale (e.g., "en-US"). If not provided, uses device's default locale

Example:

Setgreet.identifyUser(
    userId = "user123",
    attributes = mapOf(
        "name" to "John Doe",
        "email" to "john@example.com",
        "plan" to "premium"
    ),
    operation = Operation.CREATE,
    locale = "en-US"
)

Reset User

Clears user identification data and resets user session state for logout scenarios.

Example:

Setgreet.resetUser()

Show Flow

  • Setgreet Flow ID: The flow ID is a unique identifier for the flow you want to show. You can get the flow ID from the flow's URL at the web app. For example, if the flow URL is https://app.setgreet.com/flows/1234, the flow ID is 1234.

To show the Setgreet flow, call the following method:

Setgreet.showFlow(flowId = "FLOW_ID")

Track Screen

Tracks a screen view for analytics and potential flow triggers.

Parameters:

  • screenName (String): The name of the screen being viewed
  • properties (Optional): Additional properties associated with the screen view

Example:

Setgreet.trackScreen(
    screenName = "product_detail",
    properties = mapOf(
        "product_id" to "prod_123",
        "category" to "electronics",
        "price" to 299.99
    )
)

Track Event

Tracks custom events for analytics and flow triggers.

Parameters:

  • eventName (String): The name of the custom event
  • properties (Optional): Additional properties associated with the event

Example:

Setgreet.trackEvent(
    eventName = "purchase_completed",
    properties = mapOf(
        "order_id" to "ord_456",
        "total_amount" to 299.99,
        "payment_method" to "credit_card",
        "items_count" to 3
    )
)

Flow Callbacks

The SDK provides callbacks for monitoring flow lifecycle events.

Setgreet.setFlowCallbacks {
    onFlowStarted { event ->
        Log.d("Setgreet", "Flow ${event.flowId} started with ${event.screenCount} screens")
    }

    onFlowCompleted { event ->
        // User completed the flow (reached last screen)
        Analytics.log("flow_completed", mapOf(
            "flow_id" to event.flowId,
            "duration_ms" to event.durationMs
        ))
    }

    onFlowDismissed { event ->
        // User dismissed the flow before completion
        Log.d("Setgreet", "Flow dismissed: ${event.reason} at screen ${event.screenIndex + 1}")
    }

    onScreenChanged { event ->
        Log.d("Setgreet", "Screen changed: ${event.fromIndex + 1} -> ${event.toIndex + 1}")
    }

    onActionTriggered { event ->
        // User tapped a button - includes custom events from dashboard
        event.actionName?.let { customEvent ->
            Analytics.log(customEvent)
        }
    }

    onPermissionRequested { event ->
        Log.d("Setgreet", "Permission ${event.permissionType}: ${event.result}")
    }

    onError { event ->
        Log.e("Setgreet", "Error: ${event.errorType} - ${event.message}")
    }
}

Event Types

Event Description Key Properties
FlowStarted Flow begins presenting flowId, screenCount
FlowCompleted User completes the flow flowId, durationMs
FlowDismissed Flow dismissed before completion flowId, reason, screenIndex
ScreenChanged User navigates between screens fromIndex, toIndex
ActionTriggered Button action triggered actionType, actionName
PermissionRequested Permission request completed permissionType, result
FlowError Error during flow operations errorType, message

Permission Types

Type Description
notification Push notification permission
location Location access permission
camera Camera access permission

Permission Results

Result Description
granted Permission was granted by the user
denied Permission was denied by the user
permanently_denied Permission was permanently denied
already_granted Permission was already granted
not_required Permission request was not required

Dismiss Reasons

  • USER_CLOSE - User tapped the close button
  • USER_SKIP - User tapped the skip button
  • BACK_PRESS - User pressed the back button
  • REPLACED - Flow was replaced by another flow
  • PROGRAMMATIC - Flow was closed programmatically