File tree Expand file tree Collapse file tree
youtubevideotranscriptbot Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # analytics.py
2+ import logging
3+ from config import AMPLITUDE_API_KEY
4+ from amplitude import Amplitude , BaseEvent
5+
6+ logger = logging .getLogger (__name__ )
7+
8+ api_key = AMPLITUDE_API_KEY
9+ amplitude = Amplitude (api_key )
10+ # Events queued in memory will flush when number of events exceed upload threshold
11+ # Default value is 200
12+ amplitude .configuration .flush_queue_size = 20
13+
14+
15+ def track_event (user_id , event_type , event_properties = None ):
16+ """
17+ Sends an event to Amplitude.
18+
19+ :param user_id: Telegram user ID (int)
20+ :param event_type: Name of the event (e.g. 'start_command')
21+ :param event_properties: Optional dict of event metadata
22+ """
23+
24+ event = BaseEvent (
25+ user_id = str (user_id ),
26+ event_type = event_type ,
27+ event_properties = event_properties or {}
28+ )
29+
30+ try :
31+ amplitude .track (event )
32+ logger .info (f"[Amplitude] Event tracked: { event_type } for user { user_id } " )
33+ except Exception as e :
34+ logger .error (f"[Amplitude] Tracking failed: { e } " )
You can’t perform that action at this time.
0 commit comments