feat: Add analytics module with Mixpanel integration

This commit is contained in:
Paul Gauthier 2024-08-12 16:07:11 -07:00 committed by Paul Gauthier (aider)
parent b49ee06f23
commit 2e1ac25ce2

View file

@ -0,0 +1,27 @@
import uuid
from pathlib import Path
import json
from mixpanel import Mixpanel
class Analytics:
def __init__(self, project_token=None):
self.mp = Mixpanel(project_token) if project_token else None
self.user_id = self.get_or_create_uuid()
def get_or_create_uuid(self):
uuid_file = Path.home() / ".aider" / "caches" / "mixpanel-uuid.json"
uuid_file.parent.mkdir(parents=True, exist_ok=True)
if uuid_file.exists():
with open(uuid_file, 'r') as f:
return json.load(f)['uuid']
new_uuid = str(uuid.uuid4())
with open(uuid_file, 'w') as f:
json.dump({'uuid': new_uuid}, f)
return new_uuid
def track_event(self, event_name, properties=None):
if self.mp:
self.mp.track(self.user_id, event_name, properties)