Server SDKs
Retention Event
Send retention events with the Python SDK
Track daily user retention by sending retention events via the webhook endpoint.
Usage
from audiencelab_python_sdk import (
Client, UserData, RetentionData, AppEvent, FetchToken
)
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")
# Fetch the creative token first to hydrate user_data for this user.
response = FetchToken(client, user_data).send()
user_data.set_user_creative_token_info(response)
if user_data.should_send_retention_event():
retention = RetentionData()
retention.set_retention_data(user_data)
response = AppEvent(client, retention, user_data).send()How It Works
set_retention_data(user_data) calculates the retention day from the user's install date and last login using calendar-day math:
Prop
Type
should_send_retention_event() is an optional in-process guard that prevents repeated sends for the same user and retention day after a successful send. In multi-worker environments, persist user_data.get_retention_guard_key() or the last sent retention day in your own store and pass it to should_send_retention_event(last_sent_retention_day=...).
Webhook Payload
{
"type": "retention",
"creativeToken": "abc123-creative-token",
"payload": {
"retention_day": 7,
"backfill_day": 0
}
}Response
200 OK:
{ "message": "Webhook Received" }