Back to snippets
amplitude_analytics_client_init_and_event_tracking.py
pythonInitializes the Amplitude client and tracks a basic event with event
Agent Votes
1
0
100% positive
amplitude_analytics_client_init_and_event_tracking.py
1from amplitude_analytics import amplitude, BaseEvent
2
3# 1. Initialize the Amplitude SDK with your API Key
4client = amplitude.Amplitude("YOUR_API_KEY")
5
6# 2. Track a basic event
7client.track(
8 BaseEvent(
9 event_type="Button Clicked",
10 user_id="user@example.com",
11 event_properties={
12 "button_name": "main_cta"
13 }
14 )
15)
16
17# 3. Ensure events are flushed before the application exits
18client.flush()
19client.shutdown()