Generalize product analytics event tracking

This commit is contained in:
James Chu
2026-04-27 18:26:35 -04:00
parent f26d65b9c5
commit 2575cf76a4
20 changed files with 293 additions and 158 deletions
+43 -19
View File
@@ -2126,6 +2126,34 @@
],
"type": "object"
},
"ProductAnalyticsEvent": {
"oneOf": [
{
"properties": {
"action": {
"$ref": "#/definitions/UsageLimitBannerAction"
},
"bannerType": {
"$ref": "#/definitions/UsageLimitBannerType"
},
"type": {
"enum": [
"usageLimitBanner"
],
"title": "UsageLimitBannerProductAnalyticsEventType",
"type": "string"
}
},
"required": [
"action",
"bannerType",
"type"
],
"title": "UsageLimitBannerProductAnalyticsEvent",
"type": "object"
}
]
},
"RealtimeOutputModality": {
"enum": [
"text",
@@ -4082,25 +4110,14 @@
],
"type": "object"
},
"TrackUsageLimitBannerAction": {
"enum": [
"shown",
"cta_clicked"
],
"type": "string"
},
"TrackUsageLimitBannerParams": {
"TrackProductAnalyticsEventParams": {
"properties": {
"action": {
"$ref": "#/definitions/TrackUsageLimitBannerAction"
},
"bannerType": {
"$ref": "#/definitions/UsageLimitBannerType"
"event": {
"$ref": "#/definitions/ProductAnalyticsEvent"
}
},
"required": [
"action",
"bannerType"
"event"
],
"type": "object"
},
@@ -4287,6 +4304,13 @@
],
"type": "object"
},
"UsageLimitBannerAction": {
"enum": [
"shown",
"cta_clicked"
],
"type": "string"
},
"UsageLimitBannerType": {
"enum": [
"workspace_member_credits_depleted",
@@ -5843,13 +5867,13 @@
},
"method": {
"enum": [
"account/usageLimitBanner/track"
"analytics/productEvent/track"
],
"title": "Account/usageLimitBanner/trackRequestMethod",
"title": "Analytics/productEvent/trackRequestMethod",
"type": "string"
},
"params": {
"$ref": "#/definitions/TrackUsageLimitBannerParams"
"$ref": "#/definitions/TrackProductAnalyticsEventParams"
}
},
"required": [
@@ -5857,7 +5881,7 @@
"method",
"params"
],
"title": "Account/usageLimitBanner/trackRequest",
"title": "Analytics/productEvent/trackRequest",
"type": "object"
},
{
@@ -1582,13 +1582,13 @@
},
"method": {
"enum": [
"account/usageLimitBanner/track"
"analytics/productEvent/track"
],
"title": "Account/usageLimitBanner/trackRequestMethod",
"title": "Analytics/productEvent/trackRequestMethod",
"type": "string"
},
"params": {
"$ref": "#/definitions/v2/TrackUsageLimitBannerParams"
"$ref": "#/definitions/v2/TrackProductAnalyticsEventParams"
}
},
"required": [
@@ -1596,7 +1596,7 @@
"method",
"params"
],
"title": "Account/usageLimitBanner/trackRequest",
"title": "Analytics/productEvent/trackRequest",
"type": "object"
},
{
@@ -12063,6 +12063,34 @@
],
"type": "object"
},
"ProductAnalyticsEvent": {
"oneOf": [
{
"properties": {
"action": {
"$ref": "#/definitions/v2/UsageLimitBannerAction"
},
"bannerType": {
"$ref": "#/definitions/v2/UsageLimitBannerType"
},
"type": {
"enum": [
"usageLimitBanner"
],
"title": "UsageLimitBannerProductAnalyticsEventType",
"type": "string"
}
},
"required": [
"action",
"bannerType",
"type"
],
"title": "UsageLimitBannerProductAnalyticsEvent",
"type": "object"
}
]
},
"ProfileV2": {
"additionalProperties": true,
"properties": {
@@ -16917,33 +16945,22 @@
},
"type": "object"
},
"TrackUsageLimitBannerAction": {
"enum": [
"shown",
"cta_clicked"
],
"type": "string"
},
"TrackUsageLimitBannerParams": {
"TrackProductAnalyticsEventParams": {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"action": {
"$ref": "#/definitions/v2/TrackUsageLimitBannerAction"
},
"bannerType": {
"$ref": "#/definitions/v2/UsageLimitBannerType"
"event": {
"$ref": "#/definitions/v2/ProductAnalyticsEvent"
}
},
"required": [
"action",
"bannerType"
"event"
],
"title": "TrackUsageLimitBannerParams",
"title": "TrackProductAnalyticsEventParams",
"type": "object"
},
"TrackUsageLimitBannerResponse": {
"TrackProductAnalyticsEventResponse": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "TrackUsageLimitBannerResponse",
"title": "TrackProductAnalyticsEventResponse",
"type": "object"
},
"Turn": {
@@ -17370,6 +17387,13 @@
"title": "TurnSteerResponse",
"type": "object"
},
"UsageLimitBannerAction": {
"enum": [
"shown",
"cta_clicked"
],
"type": "string"
},
"UsageLimitBannerType": {
"enum": [
"workspace_member_credits_depleted",
@@ -2288,13 +2288,13 @@
},
"method": {
"enum": [
"account/usageLimitBanner/track"
"analytics/productEvent/track"
],
"title": "Account/usageLimitBanner/trackRequestMethod",
"title": "Analytics/productEvent/trackRequestMethod",
"type": "string"
},
"params": {
"$ref": "#/definitions/TrackUsageLimitBannerParams"
"$ref": "#/definitions/TrackProductAnalyticsEventParams"
}
},
"required": [
@@ -2302,7 +2302,7 @@
"method",
"params"
],
"title": "Account/usageLimitBanner/trackRequest",
"title": "Analytics/productEvent/trackRequest",
"type": "object"
},
{
@@ -8737,6 +8737,34 @@
],
"type": "object"
},
"ProductAnalyticsEvent": {
"oneOf": [
{
"properties": {
"action": {
"$ref": "#/definitions/UsageLimitBannerAction"
},
"bannerType": {
"$ref": "#/definitions/UsageLimitBannerType"
},
"type": {
"enum": [
"usageLimitBanner"
],
"title": "UsageLimitBannerProductAnalyticsEventType",
"type": "string"
}
},
"required": [
"action",
"bannerType",
"type"
],
"title": "UsageLimitBannerProductAnalyticsEvent",
"type": "object"
}
]
},
"ProfileV2": {
"additionalProperties": true,
"properties": {
@@ -14803,33 +14831,22 @@
},
"type": "object"
},
"TrackUsageLimitBannerAction": {
"enum": [
"shown",
"cta_clicked"
],
"type": "string"
},
"TrackUsageLimitBannerParams": {
"TrackProductAnalyticsEventParams": {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"action": {
"$ref": "#/definitions/TrackUsageLimitBannerAction"
},
"bannerType": {
"$ref": "#/definitions/UsageLimitBannerType"
"event": {
"$ref": "#/definitions/ProductAnalyticsEvent"
}
},
"required": [
"action",
"bannerType"
"event"
],
"title": "TrackUsageLimitBannerParams",
"title": "TrackProductAnalyticsEventParams",
"type": "object"
},
"TrackUsageLimitBannerResponse": {
"TrackProductAnalyticsEventResponse": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "TrackUsageLimitBannerResponse",
"title": "TrackProductAnalyticsEventResponse",
"type": "object"
},
"Turn": {
@@ -15256,6 +15273,13 @@
"title": "TurnSteerResponse",
"type": "object"
},
"UsageLimitBannerAction": {
"enum": [
"shown",
"cta_clicked"
],
"type": "string"
},
"UsageLimitBannerType": {
"enum": [
"workspace_member_credits_depleted",
@@ -0,0 +1,57 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"ProductAnalyticsEvent": {
"oneOf": [
{
"properties": {
"action": {
"$ref": "#/definitions/UsageLimitBannerAction"
},
"bannerType": {
"$ref": "#/definitions/UsageLimitBannerType"
},
"type": {
"enum": [
"usageLimitBanner"
],
"title": "UsageLimitBannerProductAnalyticsEventType",
"type": "string"
}
},
"required": [
"action",
"bannerType",
"type"
],
"title": "UsageLimitBannerProductAnalyticsEvent",
"type": "object"
}
]
},
"UsageLimitBannerAction": {
"enum": [
"shown",
"cta_clicked"
],
"type": "string"
},
"UsageLimitBannerType": {
"enum": [
"workspace_member_credits_depleted",
"workspace_member_usage_limit_reached"
],
"type": "string"
}
},
"properties": {
"event": {
"$ref": "#/definitions/ProductAnalyticsEvent"
}
},
"required": [
"event"
],
"title": "TrackProductAnalyticsEventParams",
"type": "object"
}
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "TrackUsageLimitBannerResponse",
"title": "TrackProductAnalyticsEventResponse",
"type": "object"
}
@@ -1,33 +0,0 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"TrackUsageLimitBannerAction": {
"enum": [
"shown",
"cta_clicked"
],
"type": "string"
},
"UsageLimitBannerType": {
"enum": [
"workspace_member_credits_depleted",
"workspace_member_usage_limit_reached"
],
"type": "string"
}
},
"properties": {
"action": {
"$ref": "#/definitions/TrackUsageLimitBannerAction"
},
"bannerType": {
"$ref": "#/definitions/UsageLimitBannerType"
}
},
"required": [
"action",
"bannerType"
],
"title": "TrackUsageLimitBannerParams",
"type": "object"
}
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { TrackUsageLimitBannerAction } from "./TrackUsageLimitBannerAction";
import type { UsageLimitBannerAction } from "./UsageLimitBannerAction";
import type { UsageLimitBannerType } from "./UsageLimitBannerType";
export type TrackUsageLimitBannerParams = { action: TrackUsageLimitBannerAction, bannerType: UsageLimitBannerType, };
export type ProductAnalyticsEvent = { "type": "usageLimitBanner", action: UsageLimitBannerAction, bannerType: UsageLimitBannerType, };
@@ -0,0 +1,6 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ProductAnalyticsEvent } from "./ProductAnalyticsEvent";
export type TrackProductAnalyticsEventParams = { event: ProductAnalyticsEvent, };
@@ -2,4 +2,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type TrackUsageLimitBannerAction = "shown" | "cta_clicked";
export type TrackProductAnalyticsEventResponse = Record<string, never>;
@@ -2,4 +2,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type TrackUsageLimitBannerResponse = Record<string, never>;
export type UsageLimitBannerAction = "shown" | "cta_clicked";
+4 -3
View File
@@ -271,6 +271,7 @@ export type { PluginSummary } from "./PluginSummary";
export type { PluginUninstallParams } from "./PluginUninstallParams";
export type { PluginUninstallResponse } from "./PluginUninstallResponse";
export type { PluginsMigration } from "./PluginsMigration";
export type { ProductAnalyticsEvent } from "./ProductAnalyticsEvent";
export type { ProfileV2 } from "./ProfileV2";
export type { RateLimitReachedType } from "./RateLimitReachedType";
export type { RateLimitSnapshot } from "./RateLimitSnapshot";
@@ -386,9 +387,8 @@ export type { ToolRequestUserInputParams } from "./ToolRequestUserInputParams";
export type { ToolRequestUserInputQuestion } from "./ToolRequestUserInputQuestion";
export type { ToolRequestUserInputResponse } from "./ToolRequestUserInputResponse";
export type { ToolsV2 } from "./ToolsV2";
export type { TrackUsageLimitBannerAction } from "./TrackUsageLimitBannerAction";
export type { TrackUsageLimitBannerParams } from "./TrackUsageLimitBannerParams";
export type { TrackUsageLimitBannerResponse } from "./TrackUsageLimitBannerResponse";
export type { TrackProductAnalyticsEventParams } from "./TrackProductAnalyticsEventParams";
export type { TrackProductAnalyticsEventResponse } from "./TrackProductAnalyticsEventResponse";
export type { Turn } from "./Turn";
export type { TurnCompletedNotification } from "./TurnCompletedNotification";
export type { TurnDiffUpdatedNotification } from "./TurnDiffUpdatedNotification";
@@ -405,6 +405,7 @@ export type { TurnStartedNotification } from "./TurnStartedNotification";
export type { TurnStatus } from "./TurnStatus";
export type { TurnSteerParams } from "./TurnSteerParams";
export type { TurnSteerResponse } from "./TurnSteerResponse";
export type { UsageLimitBannerAction } from "./UsageLimitBannerAction";
export type { UsageLimitBannerType } from "./UsageLimitBannerType";
export type { UserInput } from "./UserInput";
export type { WarningNotification } from "./WarningNotification";
@@ -573,9 +573,9 @@ client_request_definitions! {
response: v2::SendAddCreditsNudgeEmailResponse,
},
TrackUsageLimitBanner => "account/usageLimitBanner/track" {
params: v2::TrackUsageLimitBannerParams,
response: v2::TrackUsageLimitBannerResponse,
TrackProductAnalyticsEvent => "analytics/productEvent/track" {
params: v2::TrackProductAnalyticsEventParams,
response: v2::TrackProductAnalyticsEventResponse,
},
FeedbackUpload => "feedback/upload" {
@@ -1468,23 +1468,28 @@ mod tests {
}
#[test]
fn serialize_track_usage_limit_banner() -> Result<()> {
let request = ClientRequest::TrackUsageLimitBanner {
fn serialize_track_product_analytics_event() -> Result<()> {
let request = ClientRequest::TrackProductAnalyticsEvent {
request_id: RequestId::Integer(2),
params: v2::TrackUsageLimitBannerParams {
action: v2::TrackUsageLimitBannerAction::CtaClicked,
banner_type: v2::UsageLimitBannerType::WorkspaceMemberUsageLimitReached,
params: v2::TrackProductAnalyticsEventParams {
event: v2::ProductAnalyticsEvent::UsageLimitBanner {
action: v2::UsageLimitBannerAction::CtaClicked,
banner_type: v2::UsageLimitBannerType::WorkspaceMemberUsageLimitReached,
},
},
};
assert_eq!(request.id(), &RequestId::Integer(2));
assert_eq!(request.method(), "account/usageLimitBanner/track");
assert_eq!(request.method(), "analytics/productEvent/track");
assert_eq!(
json!({
"method": "account/usageLimitBanner/track",
"method": "analytics/productEvent/track",
"id": 2,
"params": {
"action": "cta_clicked",
"bannerType": "workspace_member_usage_limit_reached",
"event": {
"type": "usageLimitBanner",
"action": "cta_clicked",
"bannerType": "workspace_member_usage_limit_reached",
},
},
}),
serde_json::to_value(&request)?,
@@ -2253,15 +2253,26 @@ pub struct SendAddCreditsNudgeEmailParams {
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct TrackUsageLimitBannerParams {
pub action: TrackUsageLimitBannerAction,
pub banner_type: UsageLimitBannerType,
pub struct TrackProductAnalyticsEventParams {
pub event: ProductAnalyticsEvent,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(tag = "type", rename_all = "camelCase")]
#[ts(export_to = "v2/", tag = "type", rename_all = "camelCase")]
pub enum ProductAnalyticsEvent {
UsageLimitBanner {
action: UsageLimitBannerAction,
#[serde(rename = "bannerType")]
#[ts(rename = "bannerType")]
banner_type: UsageLimitBannerType,
},
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "snake_case")]
#[ts(export_to = "v2/", rename_all = "snake_case")]
pub enum TrackUsageLimitBannerAction {
pub enum UsageLimitBannerAction {
Shown,
CtaClicked,
}
@@ -2292,7 +2303,7 @@ pub struct SendAddCreditsNudgeEmailResponse {
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct TrackUsageLimitBannerResponse {}
pub struct TrackProductAnalyticsEventResponse {}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "snake_case")]