From c782d814e1d02bca75d74e2f208f0393d335eab6 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 18 Dec 2023 11:34:27 +0100 Subject: [PATCH] Update - refactor telemetry tracking logic in oss --- agenta-cli/agenta/cli/telemetry.py | 8 ++++++-- agenta-cli/agenta/cli/variant_commands.py | 2 -- agenta-web/src/hooks/usePostHogAg.ts | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/agenta-cli/agenta/cli/telemetry.py b/agenta-cli/agenta/cli/telemetry.py index a293ec70bd..218e241501 100644 --- a/agenta-cli/agenta/cli/telemetry.py +++ b/agenta-cli/agenta/cli/telemetry.py @@ -1,5 +1,6 @@ # Stdlib Imports import toml +from uuid import uuid4 from pathlib import Path # Own Imports @@ -26,7 +27,6 @@ def __init__(self, api_key: str, host: str) -> None: def capture_event( self, - distinct_id: str, event_name: str, body: dict, ) -> None: @@ -34,11 +34,15 @@ def capture_event( Captures an event. Args: - distinct_id (str): A unique identifier for the user or entity associated with the event. event_name (str): The name of the event being captured. body (dict): Contains the data associated with the event being captured. """ + # A unique identifier for the user or entity associated with the event + distinct_id = helper.get_global_config("telemetry_distinct_id") + if not distinct_id: + distinct_id = uuid4() + helper.set_global_config("telemetry_distinct_id", str(distinct_id)) self.capture(distinct_id, event_name, body) diff --git a/agenta-cli/agenta/cli/variant_commands.py b/agenta-cli/agenta/cli/variant_commands.py index 95104a80a6..f5581ac774 100644 --- a/agenta-cli/agenta/cli/variant_commands.py +++ b/agenta-cli/agenta/cli/variant_commands.py @@ -162,7 +162,6 @@ def add_variant( if tracking_enabled: user_id = client.retrieve_user_id(host, api_key) event_track.capture_event( - user_id, "app_deployment", body={ "app_id": app_id, @@ -184,7 +183,6 @@ def add_variant( if tracking_enabled: user_id = client.retrieve_user_id(host, api_key) event_track.capture_event( - user_id, "app_deployment", body={ "app_id": app_id, diff --git a/agenta-web/src/hooks/usePostHogAg.ts b/agenta-web/src/hooks/usePostHogAg.ts index 5a3f069dff..6b27a13a63 100644 --- a/agenta-web/src/hooks/usePostHogAg.ts +++ b/agenta-web/src/hooks/usePostHogAg.ts @@ -8,7 +8,7 @@ export const usePostHogAg = () => { const {user} = useProfileData() const posthog = usePostHog() - const _id = isDemo() ? user?.email : user?.id + const _id = isDemo() ? user?.email : null const capture: typeof posthog.capture = (...args) => { if (trackingEnabled && user?.id) { @@ -18,7 +18,7 @@ export const usePostHogAg = () => { const identify: typeof posthog.identify = (id, ...args) => { if (trackingEnabled && user?.id) { - posthog.identify(_id || id, ...args) + posthog.identify(_id !== undefined ? _id : null, ...args) } }