Server SDKs

Session Event

Send optional session start and end events with the Python SDK

Session tracking is optional for server-side integrations. Use these helpers when your backend or app can reliably track session IDs, indexes, durations, and end reasons.

Usage

from audiencelab_python_sdk import (
    Client, UserData, SessionData, AppEvent
)

client = Client(
    api_key="YOUR_API_KEY",
    base_url="https://analytics.geeklab.app"
)

user_data = UserData()
user_data.set_user_id("user_12345")
user_data.set_user_ip("203.0.113.42")
user_data.set_user_creative_token_info({
    "creative_token": "abc123-creative-token",
    "os_system": "iOS 17.4",
    "device_name": "iPhone 14 Pro",
    "device_model": "iPhone15,2",
    "utc_offset": "+03:00",
    "install_date": "2026-06-09T10:00:00.000Z",
    "last_login_date": "2026-06-09T10:00:00.000Z",
})

session_id = SessionData.generate_session_id()
session_index = 1

session_start = SessionData.start(
    session_id=session_id,
    session_index=session_index,
)
AppEvent(client, session_start, user_data).send()

session_end = SessionData.end(
    session_id=session_id,
    session_index=session_index,
    duration_seconds=342,
    reason="background_timeout",
)
AppEvent(client, session_end, user_data).send()

Regular Event Context

When available, regular purchase, ad, retention, and custom events can include session context. This is optional and does not block sending.

user_data.set_session_context(session_id, session_index)

# Or provide context for a single event:
AppEvent(
    client,
    event_data,
    user_data,
    session_id=session_id,
    session_index=session_index,
).send()

SessionData Fields

Prop

Type

Customer-Owned Session Tracking

The Python S2S SDK does not observe app lifecycle automatically. Omit session events and sid/si context when your customer environment cannot track them reliably.