Skip to content

Commit

Permalink
chore: add usage reports for js-lite (web) sdk (#26324)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Nov 26, 2024
1 parent 1e4d4ec commit a903900
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions plugin-server/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ export const KNOWN_LIB_VALUES = new Set([
'posthog-python',
'',
'js',
'posthog-js-lite',
'posthog-node',
'posthog-react-native',
'posthog-ruby',
Expand Down
2 changes: 1 addition & 1 deletion posthog/tasks/test/__snapshots__/test_usage_report.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'''

SELECT team_id,
multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', JSONExtractString(properties, '$lib') = 'web', 'web_events', JSONExtractString(properties, '$lib') = 'posthog-node', 'node_events', JSONExtractString(properties, '$lib') = 'posthog-android', 'android_events', JSONExtractString(properties, '$lib') = 'posthog-flutter', 'flutter_events', JSONExtractString(properties, '$lib') = 'posthog-ios', 'ios_events', JSONExtractString(properties, '$lib') = 'posthog-go', 'go_events', JSONExtractString(properties, '$lib') = 'posthog-java', 'java_events', JSONExtractString(properties, '$lib') = 'posthog-react-native', 'react_native_events', JSONExtractString(properties, '$lib') = 'posthog-ruby', 'ruby_events', JSONExtractString(properties, '$lib') = 'posthog-python', 'python_events', JSONExtractString(properties, '$lib') = 'posthog-php', 'php_events', 'other') AS metric,
multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', JSONExtractString(properties, '$lib') = 'web', 'web_events', JSONExtractString(properties, '$lib') = 'posthog-js-lite', 'web_lite_events', JSONExtractString(properties, '$lib') = 'posthog-node', 'node_events', JSONExtractString(properties, '$lib') = 'posthog-android', 'android_events', JSONExtractString(properties, '$lib') = 'posthog-flutter', 'flutter_events', JSONExtractString(properties, '$lib') = 'posthog-ios', 'ios_events', JSONExtractString(properties, '$lib') = 'posthog-go', 'go_events', JSONExtractString(properties, '$lib') = 'posthog-java', 'java_events', JSONExtractString(properties, '$lib') = 'posthog-react-native', 'react_native_events', JSONExtractString(properties, '$lib') = 'posthog-ruby', 'ruby_events', JSONExtractString(properties, '$lib') = 'posthog-python', 'python_events', JSONExtractString(properties, '$lib') = 'posthog-php', 'php_events', 'other') AS metric,
count(1) as count
FROM events
WHERE timestamp BETWEEN '2022-01-10 00:00:00' AND '2022-01-10 23:59:59'
Expand Down
14 changes: 10 additions & 4 deletions posthog/tasks/test/test_usage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def _create_sample_usage_data(self) -> None:
# Add events for each SDK
sdks = [
"web",
"posthog-js-lite",
"posthog-node",
"posthog-android",
"posthog-flutter",
Expand Down Expand Up @@ -499,14 +500,15 @@ def _test_usage_report(self) -> list[dict]:
},
"plugins_enabled": {"Installed and enabled": 1},
"instance_tag": "none",
"event_count_in_period": 40,
"enhanced_persons_event_count_in_period": 39,
"event_count_in_period": 41,
"enhanced_persons_event_count_in_period": 40,
"event_count_with_groups_in_period": 2,
"event_count_from_keywords_ai_in_period": 1,
"event_count_from_traceloop_in_period": 1,
"event_count_from_langfuse_in_period": 1,
"event_count_from_helicone_in_period": 1,
"web_events_count_in_period": 37,
"web_lite_events_count_in_period": 1,
"node_events_count_in_period": 1,
"android_events_count_in_period": 1,
"flutter_events_count_in_period": 1,
Expand Down Expand Up @@ -553,14 +555,15 @@ def _test_usage_report(self) -> list[dict]:
"team_count": 2,
"teams": {
str(self.org_1_team_1.id): {
"event_count_in_period": 29,
"enhanced_persons_event_count_in_period": 28,
"event_count_in_period": 30,
"enhanced_persons_event_count_in_period": 29,
"event_count_with_groups_in_period": 2,
"event_count_from_keywords_ai_in_period": 1,
"event_count_from_traceloop_in_period": 1,
"event_count_from_langfuse_in_period": 1,
"event_count_from_helicone_in_period": 1,
"web_events_count_in_period": 25,
"web_lite_events_count_in_period": 1,
"node_events_count_in_period": 1,
"android_events_count_in_period": 1,
"flutter_events_count_in_period": 1,
Expand Down Expand Up @@ -609,6 +612,7 @@ def _test_usage_report(self) -> list[dict]:
"event_count_from_langfuse_in_period": 0,
"event_count_from_helicone_in_period": 0,
"web_events_count_in_period": 12,
"web_lite_events_count_in_period": 0,
"node_events_count_in_period": 0,
"android_events_count_in_period": 0,
"flutter_events_count_in_period": 0,
Expand Down Expand Up @@ -680,6 +684,7 @@ def _test_usage_report(self) -> list[dict]:
"event_count_from_langfuse_in_period": 0,
"event_count_from_helicone_in_period": 0,
"web_events_count_in_period": 11,
"web_lite_events_count_in_period": 0,
"node_events_count_in_period": 0,
"android_events_count_in_period": 0,
"flutter_events_count_in_period": 0,
Expand Down Expand Up @@ -734,6 +739,7 @@ def _test_usage_report(self) -> list[dict]:
"event_count_from_langfuse_in_period": 0,
"event_count_from_helicone_in_period": 0,
"web_events_count_in_period": 11,
"web_lite_events_count_in_period": 0,
"node_events_count_in_period": 0,
"android_events_count_in_period": 0,
"flutter_events_count_in_period": 0,
Expand Down
5 changes: 5 additions & 0 deletions posthog/tasks/usage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class UsageReportCounters:
hog_function_fetch_calls_in_period: int
# SDK usage
web_events_count_in_period: int
web_lite_events_count_in_period: int
node_events_count_in_period: int
android_events_count_in_period: int
flutter_events_count_in_period: int
Expand Down Expand Up @@ -474,6 +475,7 @@ def get_all_event_metrics_in_period(begin: datetime, end: datetime) -> dict[str,
event LIKE 'keywords_ai%%', 'keywords_ai_events',
event LIKE 'traceloop%%', 'traceloop_events',
{lib_expression} = 'web', 'web_events',
{lib_expression} = 'posthog-js-lite', 'web_lite_events',
{lib_expression} = 'posthog-node', 'node_events',
{lib_expression} = 'posthog-android', 'android_events',
{lib_expression} = 'posthog-flutter', 'flutter_events',
Expand Down Expand Up @@ -503,6 +505,7 @@ def get_all_event_metrics_in_period(begin: datetime, end: datetime) -> dict[str,
"keywords_ai_events": [],
"traceloop_events": [],
"web_events": [],
"web_lite_events": [],
"node_events": [],
"android_events": [],
"flutter_events": [],
Expand Down Expand Up @@ -775,6 +778,7 @@ def _get_all_usage_data(period_start: datetime, period_end: datetime) -> dict[st
"teams_with_event_count_from_keywords_ai_in_period": all_metrics["keywords_ai_events"],
"teams_with_event_count_from_traceloop_in_period": all_metrics["traceloop_events"],
"teams_with_web_events_count_in_period": all_metrics["web_events"],
"teams_with_web_lite_events_count_in_period": all_metrics["web_lite_events"],
"teams_with_node_events_count_in_period": all_metrics["node_events"],
"teams_with_android_events_count_in_period": all_metrics["android_events"],
"teams_with_flutter_events_count_in_period": all_metrics["flutter_events"],
Expand Down Expand Up @@ -987,6 +991,7 @@ def _get_team_report(all_data: dict[str, Any], team: Team) -> UsageReportCounter
hog_function_calls_in_period=all_data["teams_with_hog_function_calls_in_period"].get(team.id, 0),
hog_function_fetch_calls_in_period=all_data["teams_with_hog_function_fetch_calls_in_period"].get(team.id, 0),
web_events_count_in_period=all_data["teams_with_web_events_count_in_period"].get(team.id, 0),
web_lite_events_count_in_period=all_data["teams_with_web_lite_events_count_in_period"].get(team.id, 0),
node_events_count_in_period=all_data["teams_with_node_events_count_in_period"].get(team.id, 0),
android_events_count_in_period=all_data["teams_with_android_events_count_in_period"].get(team.id, 0),
flutter_events_count_in_period=all_data["teams_with_flutter_events_count_in_period"].get(team.id, 0),
Expand Down

0 comments on commit a903900

Please sign in to comment.