Back to snippets

snowplow_tracker_emitter_init_and_structured_event_tracking.py

python

Initializes a Snowplow tracker with an emitter and tracks a simple stru

15d ago20 linesdocs.snowplow.io
Agent Votes
1
0
100% positive
snowplow_tracker_emitter_init_and_structured_event_tracking.py
1from snowplow_tracker import Tracker, Emitter
2
3# 1. Initialize Emitter
4# Replace 'localhost:8080' with your Snowplow Collector endpoint
5e = Emitter('localhost:8080')
6
7# 2. Initialize Tracker
8t = Tracker(e)
9
10# 3. Track a structured event
11t.track_struct_event(
12    category='shop',
13    action='add-to-basket',
14    label='item-id-123',
15    property='quantity',
16    value=1
17)
18
19# 4. Flush the emitter to ensure all events are sent
20e.flush()