Implementation:DataExpert io Data engineer handbook Statsig Log event
Appearance
Overview
Statsig Log Event is a Wrapper Doc implementation that documents the use of the external Statsig Python SDK to track user events within A/B experiment variants. This is the concrete realization of the Principle:DataExpert_io_Data_engineer_handbook_Event_Tracking principle.
Type
Wrapper Doc (external Statsig SDK)
Source
server.py:L34-46
Code
statsig_user = StatsigUser(user_id)
statsig_event = StatsigEvent(
user=statsig_user,
event_name='visited_signup'
)
statsig.log_event(statsig_event)
Signature
StatsigEvent(user: StatsigUser, event_name: str) -> StatsigEvent
statsig.log_event(event: StatsigEvent) -> None
Imports
from statsig.statsig_event import StatsigEvent
from statsig.statsig_user import StatsigUser
from statsig import statsig
Inputs and Outputs
| Direction | Name | Type | Description |
|---|---|---|---|
| Input | user_id | str | The user identifier, derived from either a hashed IP address (str(hash(request.remote_addr))) or a random ID via the ?random query parameter
|
| Input | event_name | str | The name of the event to log (e.g., 'visited_signup')
|
| Output | (side effect) | None | The event is logged to the Statsig platform for analytics. The function returns None; the effect is the transmission of event data to Statsig's backend.
|
Behavior
- A
StatsigUseris created from theuser_id— this must be the same identifier used for experiment assignment viastatsig.get_experiment()to ensure events are correctly associated with the user's variant - A
StatsigEventis constructed with the user and the event name statsig.log_event()sends the event to the Statsig backend asynchronously- The Statsig platform automatically correlates this event with the user's experiment variant assignment, enabling post-hoc analysis without explicit variant tagging in the event
- In the source code, the event
'visited_signup'is logged when a user visits the signup-related route, serving as a conversion event for the button color experiment
External Reference
Related Pages
- Principle:DataExpert_io_Data_engineer_handbook_Event_Tracking
- Environment:DataExpert_io_Data_engineer_handbook_Statsig_API_Environment
Metadata
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment