Skip to content

Commit

Permalink
Update - refactor telemetry tracking logic in oss
Browse files Browse the repository at this point in the history
  • Loading branch information
aybruhm committed Dec 18, 2023
1 parent 541d662 commit c782d81
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 6 additions & 2 deletions agenta-cli/agenta/cli/telemetry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Stdlib Imports
import toml
from uuid import uuid4
from pathlib import Path

# Own Imports
Expand All @@ -26,19 +27,22 @@ def __init__(self, api_key: str, host: str) -> None:

def capture_event(
self,
distinct_id: str,
event_name: str,
body: dict,
) -> None:
"""
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)


Expand Down
2 changes: 0 additions & 2 deletions agenta-cli/agenta/cli/variant_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions agenta-web/src/hooks/usePostHogAg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}

Expand Down

0 comments on commit c782d81

Please sign in to comment.