Sessions & Events

Understanding sessions and events is fundamental to using Amply SDK effectively. This guide covers how they work and best practices for implementation.

Sessions

A session represents a period of user activity within your app. The SDK manages sessions automatically, but understanding their lifecycle helps you build better analytics.

Session Lifecycle

App Launch → Session Start → User Activity → Inactivity → Session End

                              New Activity → Session Resume or New Session

Session Properties

Each session tracks:

Property
Description

counter

Total number of sessions for this user

duration

Time elapsed since session start

eventCount

Number of events in current session

Accessing Session Data

// Get session dataset snapshot
val sessionData = amply.getDataSetSnapshot(DataSetType.Session)
// Returns: { "counter": 5 }

Events

Events capture discrete user actions and system occurrences. They form the basis for analytics and campaign triggering.

Event Types

Type
Description
Example

Custom

User-triggered actions

button_clicked, purchase_completed

System

SDK-generated events

SDK_INITIALIZED, SESSION_START

Tracking Custom Events

System Events

The SDK automatically tracks these system events:

Event
When Fired

SDK_INITIALIZED

SDK initialization complete

SESSION_START

New session begins

SESSION_END

Session ends

CAMPAIGNS_LOADED

Campaigns fetched from server

Listening to System Events

Event Properties

Properties add context to events. They can be used in campaign targeting and analytics.

Property Types

Events support these property value types:

  • String

  • Int / Long

  • Double / Float

  • Boolean

Best Practices

1

Use consistent naming

Stick to a naming convention (e.g., snake_case).

2

Keep properties flat

Avoid nested objects.

3

Be specific

purchase_completed is better than action.

4

Include context

Add relevant IDs, categories, values.

Example Event Schema

Event Counters

The SDK maintains counters for events, useful for campaign triggering:

Counter Type
Scope
Use Case

Global

All time

"Show after 10th purchase ever"

Session

Current session

"Show after 3rd view this session"

Accessing Event Counters

Retrieving Recent Events

Last updated