4343from openadapt .models import Recording
4444from openadapt .replay import replay
4545from openadapt .strategies .base import BaseReplayStrategy
46+ from openadapt .utils import get_posthog_instance
4647from openadapt .visualize import main as visualize
4748
4849# ensure all strategies are registered
5152ICON_PATH = os .path .join (FPATH , "assets" , "logo.png" )
5253
5354
55+ class TrackedQAction (QAction ):
56+ """QAction that tracks the recording state."""
57+
58+ def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
59+ """Initialize the TrackedQAction.
60+
61+ Args:
62+ text (str): The text of the action.
63+ parent (QWidget): The parent widget.
64+ """
65+ super ().__init__ (* args , ** kwargs )
66+ self .triggered .connect (self .track_event )
67+
68+ def track_event (self ) -> None :
69+ """Track the event."""
70+ posthog = get_posthog_instance ()
71+ posthog .capture (event = "action_triggered" , properties = {"action" : self .text ()})
72+
73+
5474class SystemTrayIcon :
5575 """System tray icon for OpenAdapt."""
5676
@@ -94,7 +114,7 @@ def __init__(self) -> None:
94114
95115 self .menu = QMenu ()
96116
97- self .record_action = QAction ("Record" )
117+ self .record_action = TrackedQAction ("Record" )
98118 self .record_action .triggered .connect (self ._record )
99119 self .menu .addAction (self .record_action )
100120
@@ -104,15 +124,15 @@ def __init__(self) -> None:
104124 self .populate_menus ()
105125
106126 # TODO: Remove this action once dashboard is integrated
107- # self.app_action = QAction ("Show App")
127+ # self.app_action = TrackedQAction ("Show App")
108128 # self.app_action.triggered.connect(self.show_app)
109129 # self.menu.addAction(self.app_action)
110130
111- self .dashboard_action = QAction ("Launch Dashboard" )
131+ self .dashboard_action = TrackedQAction ("Launch Dashboard" )
112132 self .dashboard_action .triggered .connect (self .launch_dashboard )
113133 self .menu .addAction (self .dashboard_action )
114134
115- self .quit = QAction ("Quit" )
135+ self .quit = TrackedQAction ("Quit" )
116136
117137 def _quit () -> None :
118138 """Quit the application."""
@@ -424,7 +444,7 @@ def populate_menu(self, menu: QMenu, action: Callable, action_type: str) -> None
424444 self .recording_actions [action_type ] = []
425445
426446 if not recordings :
427- no_recordings_action = QAction ("No recordings available" )
447+ no_recordings_action = TrackedQAction ("No recordings available" )
428448 no_recordings_action .setEnabled (False )
429449 menu .addAction (no_recordings_action )
430450 self .recording_actions [action_type ].append (no_recordings_action )
@@ -434,7 +454,7 @@ def populate_menu(self, menu: QMenu, action: Callable, action_type: str) -> None
434454 recording .timestamp
435455 ).strftime ("%Y-%m-%d %H:%M:%S" )
436456 action_text = f"{ formatted_timestamp } : { recording .task_description } "
437- recording_action = QAction (action_text )
457+ recording_action = TrackedQAction (action_text )
438458 recording_action .triggered .connect (partial (action , recording ))
439459 self .recording_actions [action_type ].append (recording_action )
440460 menu .addAction (recording_action )
0 commit comments