diff --git a/packages/api-client/src/client.test.ts b/packages/api-client/src/client.test.ts index 14355b1aa..276de990e 100644 --- a/packages/api-client/src/client.test.ts +++ b/packages/api-client/src/client.test.ts @@ -80,6 +80,27 @@ describe('UmamiClient', () => { expect(JSON.parse(calls[0].body as string)).toMatchObject({ websiteId: 'w1', type: 'funnel' }); }); + test('sends structured funnel criteria through the GET stats API', async () => { + const { client, calls } = createClient([]); + const steps = [ + { type: 'path', value: '/a?x=1&y=日本語' }, + { type: 'event', value: 'signup' }, + ]; + await client.getWebsiteFunnelStats({ + websiteId: 'w1', + startAt: 1, + endAt: 2, + window: 60, + steps: JSON.stringify(steps), + browser1: 'eq.Chrome', + }); + expect(calls[0].method).toBe('GET'); + expect(calls[0].body).toBeUndefined(); + expect(calls[0].url.pathname).toBe('/api/websites/w1/funnels/stats'); + expect(JSON.parse(calls[0].url.searchParams.get('steps')!)).toEqual(steps); + expect(calls[0].url.searchParams.get('browser1')).toBe('eq.Chrome'); + }); + test('uses the Cloud base URL and API key header by default', async () => { const calls: Captured[] = []; const client = new UmamiClient({ diff --git a/packages/api-client/src/generated/operations.ts b/packages/api-client/src/generated/operations.ts index 26c82615d..56a991a96 100644 --- a/packages/api-client/src/generated/operations.ts +++ b/packages/api-client/src/generated/operations.ts @@ -162,6 +162,22 @@ export const operations = { queryParams: [], hasBody: true, }, + createWebsiteFunnel: { + operationId: 'createWebsiteFunnel', + method: 'post', + path: '/api/websites/{websiteId}/funnels', + pathParams: ['websiteId'], + queryParams: [], + hasBody: true, + }, + createWebsiteGoal: { + operationId: 'createWebsiteGoal', + method: 'post', + path: '/api/websites/{websiteId}/goals', + pathParams: ['websiteId'], + queryParams: [], + hasBody: true, + }, createWebsiteSegment: { operationId: 'createWebsiteSegment', method: 'post', @@ -266,6 +282,22 @@ export const operations = { queryParams: [], hasBody: false, }, + deleteWebsiteFunnel: { + operationId: 'deleteWebsiteFunnel', + method: 'delete', + path: '/api/websites/{websiteId}/funnels/{funnelId}', + pathParams: ['websiteId', 'funnelId'], + queryParams: [], + hasBody: false, + }, + deleteWebsiteGoal: { + operationId: 'deleteWebsiteGoal', + method: 'delete', + path: '/api/websites/{websiteId}/goals/{goalId}', + pathParams: ['websiteId', 'goalId'], + queryParams: [], + hasBody: false, + }, deleteWebsiteSegment: { operationId: 'deleteWebsiteSegment', method: 'delete', @@ -1549,6 +1581,87 @@ export const operations = { queryParams: ['startAt', 'endAt', 'search', 'page', 'pageSize', 'maxResults'], hasBody: false, }, + getWebsiteAttribution: { + operationId: 'getWebsiteAttribution', + method: 'get', + path: '/api/websites/{websiteId}/attribution', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + 'model', + 'type', + 'step', + 'currency', + ], + hasBody: false, + }, + getWebsiteBreakdown: { + operationId: 'getWebsiteBreakdown', + method: 'get', + path: '/api/websites/{websiteId}/breakdown', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + 'fields', + ], + hasBody: false, + }, getWebsiteDateRange: { operationId: 'getWebsiteDateRange', method: 'get', @@ -1727,6 +1840,199 @@ export const operations = { ], hasBody: false, }, + getWebsiteFunnel: { + operationId: 'getWebsiteFunnel', + method: 'get', + path: '/api/websites/{websiteId}/funnels/{funnelId}', + pathParams: ['websiteId', 'funnelId'], + queryParams: [], + hasBody: false, + }, + getWebsiteFunnels: { + operationId: 'getWebsiteFunnels', + method: 'get', + path: '/api/websites/{websiteId}/funnels', + pathParams: ['websiteId'], + queryParams: ['page', 'pageSize', 'maxResults', 'search'], + hasBody: false, + }, + getWebsiteFunnelStats: { + operationId: 'getWebsiteFunnelStats', + method: 'get', + path: '/api/websites/{websiteId}/funnels/stats', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + 'window', + 'steps', + ], + hasBody: false, + }, + getWebsiteGoal: { + operationId: 'getWebsiteGoal', + method: 'get', + path: '/api/websites/{websiteId}/goals/{goalId}', + pathParams: ['websiteId', 'goalId'], + queryParams: [], + hasBody: false, + }, + getWebsiteGoals: { + operationId: 'getWebsiteGoals', + method: 'get', + path: '/api/websites/{websiteId}/goals', + pathParams: ['websiteId'], + queryParams: ['page', 'pageSize', 'maxResults', 'search'], + hasBody: false, + }, + getWebsiteGoalStats: { + operationId: 'getWebsiteGoalStats', + method: 'get', + path: '/api/websites/{websiteId}/goals/stats', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + 'type', + 'value', + ], + hasBody: false, + }, + getWebsiteHeatmaps: { + operationId: 'getWebsiteHeatmaps', + method: 'get', + path: '/api/websites/{websiteId}/heatmaps', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + 'urlPath', + 'mode', + ], + hasBody: false, + }, + getWebsiteJourneys: { + operationId: 'getWebsiteJourneys', + method: 'get', + path: '/api/websites/{websiteId}/journeys', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + 'steps', + 'startStep', + 'endStep', + ], + hasBody: false, + }, getWebsiteMetrics: { operationId: 'getWebsiteMetrics', method: 'get', @@ -1813,6 +2119,124 @@ export const operations = { ], hasBody: false, }, + getWebsitePerformanceChart: { + operationId: 'getWebsitePerformanceChart', + method: 'get', + path: '/api/websites/{websiteId}/performance/chart', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + 'metric', + ], + hasBody: false, + }, + getWebsitePerformanceMetrics: { + operationId: 'getWebsitePerformanceMetrics', + method: 'get', + path: '/api/websites/{websiteId}/performance/metrics', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + 'metric', + 'type', + 'limit', + ], + hasBody: false, + }, + getWebsitePerformanceStats: { + operationId: 'getWebsitePerformanceStats', + method: 'get', + path: '/api/websites/{websiteId}/performance/stats', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + ], + hasBody: false, + }, getWebsiteRecorderConfig: { operationId: 'getWebsiteRecorderConfig', method: 'get', @@ -1891,6 +2315,44 @@ export const operations = { queryParams: ['type', 'page', 'pageSize', 'maxResults'], hasBody: false, }, + getWebsiteRetention: { + operationId: 'getWebsiteRetention', + method: 'get', + path: '/api/websites/{websiteId}/retention', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + ], + hasBody: false, + }, getWebsiteRevenueChart: { operationId: 'getWebsiteRevenueChart', method: 'get', @@ -2064,6 +2526,82 @@ export const operations = { ], hasBody: false, }, + getWebsiteSavedFunnelStats: { + operationId: 'getWebsiteSavedFunnelStats', + method: 'get', + path: '/api/websites/{websiteId}/funnels/{funnelId}/stats', + pathParams: ['websiteId', 'funnelId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + ], + hasBody: false, + }, + getWebsiteSavedGoalStats: { + operationId: 'getWebsiteSavedGoalStats', + method: 'get', + path: '/api/websites/{websiteId}/goals/{goalId}/stats', + pathParams: ['websiteId', 'goalId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + ], + hasBody: false, + }, getWebsiteSavedReplays: { operationId: 'getWebsiteSavedReplays', method: 'get', @@ -2336,6 +2874,45 @@ export const operations = { ], hasBody: false, }, + getWebsiteUtmMetrics: { + operationId: 'getWebsiteUtmMetrics', + method: 'get', + path: '/api/websites/{websiteId}/utm/metrics', + pathParams: ['websiteId'], + queryParams: [ + 'path', + 'referrer', + 'title', + 'query', + 'os', + 'browser', + 'device', + 'country', + 'region', + 'city', + 'tag', + 'hostname', + 'distinctId', + 'language', + 'event', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + 'segment', + 'cohort', + 'eventType', + 'excludeBounce', + 'match', + 'startAt', + 'endAt', + 'timezone', + 'unit', + 'type', + ], + hasBody: false, + }, getWebsiteValues: { operationId: 'getWebsiteValues', method: 'get', @@ -2618,6 +3195,22 @@ export const operations = { queryParams: [], hasBody: true, }, + updateWebsiteFunnel: { + operationId: 'updateWebsiteFunnel', + method: 'post', + path: '/api/websites/{websiteId}/funnels/{funnelId}', + pathParams: ['websiteId', 'funnelId'], + queryParams: [], + hasBody: true, + }, + updateWebsiteGoal: { + operationId: 'updateWebsiteGoal', + method: 'post', + path: '/api/websites/{websiteId}/goals/{goalId}', + pathParams: ['websiteId', 'goalId'], + queryParams: [], + hasBody: true, + }, updateWebsiteSegment: { operationId: 'updateWebsiteSegment', method: 'post', @@ -2900,6 +3493,28 @@ export abstract class GeneratedUmamiClient { return this.execute('createWebsiteAnnotation', input, options); } + /** + * Create website funnel + * `POST /api/websites/{websiteId}/funnels` + */ + createWebsiteFunnel( + input: OperationInput<'createWebsiteFunnel'>, + options?: RequestOptions, + ): Promise> { + return this.execute('createWebsiteFunnel', input, options); + } + + /** + * Create website goal + * `POST /api/websites/{websiteId}/goals` + */ + createWebsiteGoal( + input: OperationInput<'createWebsiteGoal'>, + options?: RequestOptions, + ): Promise> { + return this.execute('createWebsiteGoal', input, options); + } + /** * Create a website segment or cohort * Saves a named segment or cohort with its type and filter parameters for the website. @@ -3056,6 +3671,28 @@ export abstract class GeneratedUmamiClient { return this.execute('deleteWebsiteAnnotation', input, options); } + /** + * Delete website funnel + * `DELETE /api/websites/{websiteId}/funnels/{funnelId}` + */ + deleteWebsiteFunnel( + input: OperationInput<'deleteWebsiteFunnel'>, + options?: RequestOptions, + ): Promise> { + return this.execute('deleteWebsiteFunnel', input, options); + } + + /** + * Delete website goal + * `DELETE /api/websites/{websiteId}/goals/{goalId}` + */ + deleteWebsiteGoal( + input: OperationInput<'deleteWebsiteGoal'>, + options?: RequestOptions, + ): Promise> { + return this.execute('deleteWebsiteGoal', input, options); + } + /** * Delete a website segment or cohort * Deletes the specified saved segment or cohort from the website. @@ -3812,6 +4449,28 @@ export abstract class GeneratedUmamiClient { return this.execute('getWebsiteAnnotations', input, options); } + /** + * Get website attribution + * `GET /api/websites/{websiteId}/attribution` + */ + getWebsiteAttribution( + input: OperationInput<'getWebsiteAttribution'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteAttribution', input, options); + } + + /** + * Get website breakdown + * `GET /api/websites/{websiteId}/breakdown` + */ + getWebsiteBreakdown( + input: OperationInput<'getWebsiteBreakdown'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteBreakdown', input, options); + } + /** * Get the website's available date range * Returns the earliest and latest recorded event dates for the website. @@ -3872,6 +4531,94 @@ export abstract class GeneratedUmamiClient { return this.execute('getWebsiteExpandedMetrics', input, options); } + /** + * Get website funnel + * `GET /api/websites/{websiteId}/funnels/{funnelId}` + */ + getWebsiteFunnel( + input: OperationInput<'getWebsiteFunnel'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteFunnel', input, options); + } + + /** + * Get website funnels + * `GET /api/websites/{websiteId}/funnels` + */ + getWebsiteFunnels( + input: OperationInput<'getWebsiteFunnels'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteFunnels', input, options); + } + + /** + * Get website funnel stats + * `GET /api/websites/{websiteId}/funnels/stats` + */ + getWebsiteFunnelStats( + input: OperationInput<'getWebsiteFunnelStats'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteFunnelStats', input, options); + } + + /** + * Get website goal + * `GET /api/websites/{websiteId}/goals/{goalId}` + */ + getWebsiteGoal( + input: OperationInput<'getWebsiteGoal'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteGoal', input, options); + } + + /** + * Get website goals + * `GET /api/websites/{websiteId}/goals` + */ + getWebsiteGoals( + input: OperationInput<'getWebsiteGoals'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteGoals', input, options); + } + + /** + * Get website goal stats + * `GET /api/websites/{websiteId}/goals/stats` + */ + getWebsiteGoalStats( + input: OperationInput<'getWebsiteGoalStats'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteGoalStats', input, options); + } + + /** + * Get website heatmaps + * `GET /api/websites/{websiteId}/heatmaps` + */ + getWebsiteHeatmaps( + input: OperationInput<'getWebsiteHeatmaps'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteHeatmaps', input, options); + } + + /** + * Get website journeys + * `GET /api/websites/{websiteId}/journeys` + */ + getWebsiteJourneys( + input: OperationInput<'getWebsiteJourneys'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteJourneys', input, options); + } + /** * Get ranked website metrics * Returns the most frequent values for a dimension such as pages, referrers, countries, browsers, campaigns, or events. Counts pageviews or events for activity dimensions and unique visitors for visitor dimensions. @@ -3896,6 +4643,39 @@ export abstract class GeneratedUmamiClient { return this.execute('getWebsitePageviews', input, options); } + /** + * Get website performance chart + * `GET /api/websites/{websiteId}/performance/chart` + */ + getWebsitePerformanceChart( + input: OperationInput<'getWebsitePerformanceChart'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsitePerformanceChart', input, options); + } + + /** + * Get website performance metrics + * `GET /api/websites/{websiteId}/performance/metrics` + */ + getWebsitePerformanceMetrics( + input: OperationInput<'getWebsitePerformanceMetrics'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsitePerformanceMetrics', input, options); + } + + /** + * Get website performance stats + * `GET /api/websites/{websiteId}/performance/stats` + */ + getWebsitePerformanceStats( + input: OperationInput<'getWebsitePerformanceStats'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsitePerformanceStats', input, options); + } + /** * Get website recording settings * Returns public replay and heatmap settings, including sampling, masking, and duration limits. Returns disabled status when recording is unavailable. @@ -3956,6 +4736,17 @@ export abstract class GeneratedUmamiClient { return this.execute('getWebsiteReports', input, options); } + /** + * Get website retention + * `GET /api/websites/{websiteId}/retention` + */ + getWebsiteRetention( + input: OperationInput<'getWebsiteRetention'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteRetention', input, options); + } + /** * Get website revenue over time * Returns revenue chart data for the selected currency, date range, and website filters. @@ -4004,6 +4795,28 @@ export abstract class GeneratedUmamiClient { return this.execute('getWebsiteRevenueStats', input, options); } + /** + * Get website saved funnel stats + * `GET /api/websites/{websiteId}/funnels/{funnelId}/stats` + */ + getWebsiteSavedFunnelStats( + input: OperationInput<'getWebsiteSavedFunnelStats'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteSavedFunnelStats', input, options); + } + + /** + * Get website saved goal stats + * `GET /api/websites/{websiteId}/goals/{goalId}/stats` + */ + getWebsiteSavedGoalStats( + input: OperationInput<'getWebsiteSavedGoalStats'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteSavedGoalStats', input, options); + } + /** * List saved session replays * Returns a paginated, searchable list of replays saved for the website. @@ -4160,6 +4973,17 @@ export abstract class GeneratedUmamiClient { return this.execute('getWebsiteStats', input, options); } + /** + * Get website utm metrics + * `GET /api/websites/{websiteId}/utm/metrics` + */ + getWebsiteUtmMetrics( + input: OperationInput<'getWebsiteUtmMetrics'>, + options?: RequestOptions, + ): Promise> { + return this.execute('getWebsiteUtmMetrics', input, options); + } + /** * List website filter values * Returns available values for a website filter, including saved segments or cohorts when requested, to populate filter choices. @@ -4550,6 +5374,28 @@ export abstract class GeneratedUmamiClient { return this.execute('updateWebsiteAnnotation', input, options); } + /** + * Update website funnel + * `POST /api/websites/{websiteId}/funnels/{funnelId}` + */ + updateWebsiteFunnel( + input: OperationInput<'updateWebsiteFunnel'>, + options?: RequestOptions, + ): Promise> { + return this.execute('updateWebsiteFunnel', input, options); + } + + /** + * Update website goal + * `POST /api/websites/{websiteId}/goals/{goalId}` + */ + updateWebsiteGoal( + input: OperationInput<'updateWebsiteGoal'>, + options?: RequestOptions, + ): Promise> { + return this.execute('updateWebsiteGoal', input, options); + } + /** * Update a website segment or cohort * Updates a saved segment or cohort's type, name, and filter parameters. diff --git a/packages/api-client/src/generated/types.ts b/packages/api-client/src/generated/types.ts index 61ed1616f..60d8a537f 100644 --- a/packages/api-client/src/generated/types.ts +++ b/packages/api-client/src/generated/types.ts @@ -1662,6 +1662,40 @@ export interface paths { patch?: never; trace?: never; }; + '/api/websites/{websiteId}/attribution': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website attribution */ + get: operations['getWebsiteAttribution']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/breakdown': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website breakdown */ + get: operations['getWebsiteBreakdown']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; '/api/websites/{websiteId}/daterange': { parameters: { query?: never; @@ -2022,6 +2056,182 @@ export interface paths { patch?: never; trace?: never; }; + '/api/websites/{websiteId}/funnels': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website funnels */ + get: operations['getWebsiteFunnels']; + put?: never; + /** Create website funnel */ + post: operations['createWebsiteFunnel']; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/funnels/{funnelId}': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website funnel */ + get: operations['getWebsiteFunnel']; + put?: never; + /** Update website funnel */ + post: operations['updateWebsiteFunnel']; + /** Delete website funnel */ + delete: operations['deleteWebsiteFunnel']; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/funnels/{funnelId}/stats': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website saved funnel stats */ + get: operations['getWebsiteSavedFunnelStats']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/funnels/stats': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website funnel stats */ + get: operations['getWebsiteFunnelStats']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/goals': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website goals */ + get: operations['getWebsiteGoals']; + put?: never; + /** Create website goal */ + post: operations['createWebsiteGoal']; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/goals/{goalId}': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website goal */ + get: operations['getWebsiteGoal']; + put?: never; + /** Update website goal */ + post: operations['updateWebsiteGoal']; + /** Delete website goal */ + delete: operations['deleteWebsiteGoal']; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/goals/{goalId}/stats': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website saved goal stats */ + get: operations['getWebsiteSavedGoalStats']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/goals/stats': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website goal stats */ + get: operations['getWebsiteGoalStats']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/heatmaps': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website heatmaps */ + get: operations['getWebsiteHeatmaps']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/journeys': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website journeys */ + get: operations['getWebsiteJourneys']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; '/api/websites/{websiteId}/metrics': { parameters: { query?: never; @@ -2082,6 +2292,57 @@ export interface paths { patch?: never; trace?: never; }; + '/api/websites/{websiteId}/performance/chart': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website performance chart */ + get: operations['getWebsitePerformanceChart']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/performance/metrics': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website performance metrics */ + get: operations['getWebsitePerformanceMetrics']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + '/api/websites/{websiteId}/performance/stats': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website performance stats */ + get: operations['getWebsitePerformanceStats']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; '/api/websites/{websiteId}/recorder': { parameters: { query?: never; @@ -2226,6 +2487,23 @@ export interface paths { patch?: never; trace?: never; }; + '/api/websites/{websiteId}/retention': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website retention */ + get: operations['getWebsiteRetention']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; '/api/websites/{websiteId}/revenue/chart': { parameters: { query?: never; @@ -2746,6 +3024,23 @@ export interface paths { patch?: never; trace?: never; }; + '/api/websites/{websiteId}/utm/metrics': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get website utm metrics */ + get: operations['getWebsiteUtmMetrics']; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; '/api/websites/{websiteId}/values': { parameters: { query?: never; @@ -14309,6 +14604,343 @@ export interface operations { }; }; }; + getWebsiteAttribution: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Currency code used for revenue values. */ + currency?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + model: 'first-click' | 'last-click'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + step: string; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Type of resource or analytics dimension to return. */ + type: 'path' | 'event'; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + paidAds: { + /** @description Display name of the resource. */ + name: string; + value: number; + }[]; + /** @description URL of the referring page. */ + referrer: { + /** @description Display name of the resource. */ + name: string; + value: number; + }[]; + total: { + /** @description Pageview counts for the selected period. */ + pageviews: number; + /** @description Unique visitor counts for the selected period. */ + visitors: number; + /** @description Visit counts for the selected period. */ + visits: number; + }; + utm_campaign: { + /** @description Display name of the resource. */ + name: string; + value: number; + }[]; + utm_content: { + /** @description Display name of the resource. */ + name: string; + value: number; + }[]; + utm_medium: { + /** @description Display name of the resource. */ + name: string; + value: number; + }[]; + utm_source: { + /** @description Display name of the resource. */ + name: string; + value: number; + }[]; + utm_term: { + /** @description Display name of the resource. */ + name: string; + value: number; + }[]; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsiteBreakdown: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + fields: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': ({ + /** @description Number of visits with only one pageview. */ + bounces: number; + /** @description Total visit duration in seconds. */ + totaltime: number; + /** @description Pageview counts for the selected period. */ + views: number; + /** @description Unique visitor counts for the selected period. */ + visitors: number; + /** @description Visit counts for the selected period. */ + visits: number; + } & { + [key: string]: string | number; + })[]; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; getWebsiteDateRange: { parameters: { query?: never; @@ -16467,6 +17099,1981 @@ export interface operations { }; }; }; + getWebsiteFunnels: { + parameters: { + query?: { + /** @description Maximum number of results to include. */ + maxResults?: number; + /** @description Page number, starting at 1. */ + page?: number; + /** @description Number of results per page. */ + pageSize?: number; + /** @description Search text used to filter results. */ + search?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + /** @description Number of matching records. */ + count: number; + /** @description Data returned by the operation. */ + data: ({ + /** + * Format: date-time + * @description Date and time the record was created. + */ + createdAt: string; + /** @description Description of the resource. */ + description: string; + /** @description Unique identifier of the resource. */ + id: string; + /** @description Display name of the resource. */ + name: string; + /** @description Configuration parameters for the resource. */ + parameters: + | string + | number + | false + | true + | { + [key: string]: + | string + | number + | false + | true + | unknown + | { + length: number; + }; + } + | { + length: number; + }; + type: string; + /** + * Format: date-time + * @description Date and time the record was last updated. + */ + updatedAt: string; + /** @description ID of the associated user. */ + userId: string; + /** @description ID of the website. */ + websiteId: string; + } & { + website?: { + /** @description Domain name associated with the resource. */ + domain: string; + /** @description ID of the associated user. */ + userId: string; + }; + })[]; + /** @description Whether the results were truncated by the maximum result limit. */ + isCapped?: boolean; + /** @description Field to sort the results by. */ + orderBy?: string; + /** @description Page number, starting at 1. */ + page: number; + /** @description Number of results per page. */ + pageSize: number; + /** @description Search text used to filter results. */ + search?: string; + /** @description Whether to sort results in descending order. */ + sortDescending?: boolean; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + createWebsiteFunnel: { + parameters: { + query?: never; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody: { + content: { + 'application/json': { + /** @description Description of the resource. */ + description?: string; + /** @description Display name of the resource. */ + name: string; + /** @description Configuration parameters for the resource. */ + parameters: { + steps: { + /** @description Filters applied to the analytics data. */ + filters?: { + /** @enum {string} */ + operator: 'eq' | 'neq' | 'c' | 'dnc'; + property: string; + value: string; + }[]; + /** @enum {string} */ + type: 'path' | 'event'; + value: string; + }[]; + window: number; + }; + }; + }; + }; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + /** + * @description Whether the operation succeeded. + * @constant + */ + ok: true; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsiteFunnel: { + parameters: { + query?: never; + header?: never; + path: { + funnelId: string; + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + /** + * @description Whether the operation succeeded. + * @constant + */ + ok: true; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + updateWebsiteFunnel: { + parameters: { + query?: never; + header?: never; + path: { + funnelId: string; + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody: { + content: { + 'application/json': { + /** @description Description of the resource. */ + description?: string; + /** @description Display name of the resource. */ + name: string; + /** @description Configuration parameters for the resource. */ + parameters: { + steps: { + /** @description Filters applied to the analytics data. */ + filters?: { + /** @enum {string} */ + operator: 'eq' | 'neq' | 'c' | 'dnc'; + property: string; + value: string; + }[]; + /** @enum {string} */ + type: 'path' | 'event'; + value: string; + }[]; + window: number; + }; + }; + }; + }; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + /** + * @description Whether the operation succeeded. + * @constant + */ + ok: true; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + deleteWebsiteFunnel: { + parameters: { + query?: never; + header?: never; + path: { + funnelId: string; + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Deleted successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': components['schemas']['Ok']; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsiteSavedFunnelStats: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + funnelId: string; + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + dropoff: number; + dropped: number; + /** @description Filters applied to the analytics data. */ + filters?: { + operator: string; + property: string; + value: string; + }[]; + previous: number; + remaining: number; + type: string; + value: string; + /** @description Unique visitor counts for the selected period. */ + visitors: number; + }[]; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsiteFunnelStats: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + steps: string; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + window: number; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + dropoff: number; + dropped: number; + /** @description Filters applied to the analytics data. */ + filters?: { + operator: string; + property: string; + value: string; + }[]; + previous: number; + remaining: number; + type: string; + value: string; + /** @description Unique visitor counts for the selected period. */ + visitors: number; + }[]; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsiteGoals: { + parameters: { + query?: { + /** @description Maximum number of results to include. */ + maxResults?: number; + /** @description Page number, starting at 1. */ + page?: number; + /** @description Number of results per page. */ + pageSize?: number; + /** @description Search text used to filter results. */ + search?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + /** @description Number of matching records. */ + count: number; + /** @description Data returned by the operation. */ + data: ({ + /** + * Format: date-time + * @description Date and time the record was created. + */ + createdAt: string; + /** @description Description of the resource. */ + description: string; + /** @description Unique identifier of the resource. */ + id: string; + /** @description Display name of the resource. */ + name: string; + /** @description Configuration parameters for the resource. */ + parameters: + | string + | number + | false + | true + | { + [key: string]: + | string + | number + | false + | true + | unknown + | { + length: number; + }; + } + | { + length: number; + }; + type: string; + /** + * Format: date-time + * @description Date and time the record was last updated. + */ + updatedAt: string; + /** @description ID of the associated user. */ + userId: string; + /** @description ID of the website. */ + websiteId: string; + } & { + website?: { + /** @description Domain name associated with the resource. */ + domain: string; + /** @description ID of the associated user. */ + userId: string; + }; + })[]; + /** @description Whether the results were truncated by the maximum result limit. */ + isCapped?: boolean; + /** @description Field to sort the results by. */ + orderBy?: string; + /** @description Page number, starting at 1. */ + page: number; + /** @description Number of results per page. */ + pageSize: number; + /** @description Search text used to filter results. */ + search?: string; + /** @description Whether to sort results in descending order. */ + sortDescending?: boolean; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + createWebsiteGoal: { + parameters: { + query?: never; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody: { + content: { + 'application/json': { + /** @description Description of the resource. */ + description?: string; + /** @description Display name of the resource. */ + name: string; + /** @description Configuration parameters for the resource. */ + parameters: { + type: string; + value: string; + }; + }; + }; + }; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + /** + * @description Whether the operation succeeded. + * @constant + */ + ok: true; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsiteGoal: { + parameters: { + query?: never; + header?: never; + path: { + goalId: string; + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + /** + * @description Whether the operation succeeded. + * @constant + */ + ok: true; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + updateWebsiteGoal: { + parameters: { + query?: never; + header?: never; + path: { + goalId: string; + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody: { + content: { + 'application/json': { + /** @description Description of the resource. */ + description?: string; + /** @description Display name of the resource. */ + name: string; + /** @description Configuration parameters for the resource. */ + parameters: { + type: string; + value: string; + }; + }; + }; + }; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + /** + * @description Whether the operation succeeded. + * @constant + */ + ok: true; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + deleteWebsiteGoal: { + parameters: { + query?: never; + header?: never; + path: { + goalId: string; + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Deleted successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': components['schemas']['Ok']; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsiteSavedGoalStats: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + goalId: string; + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + num: number; + total: number; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsiteGoalStats: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Type of resource or analytics dimension to return. */ + type: string; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + value: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + num: number; + total: number; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsiteHeatmaps: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + mode?: 'click' | 'scroll'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description Path portion of the page URL. */ + urlPath?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + mode: 'click' | 'scroll'; + pages: { + /** @description Number of matching records. */ + count: number; + sessions: number; + /** @description Path portion of the page URL. */ + urlPath: string; + }[]; + points: { + /** @description Number of matching records. */ + count: number; + /** @description Page height in pixels. */ + pageH: number; + /** @description Page width in pixels. */ + pageW: number; + /** @description Horizontal position on the page in pixels. */ + pageX: number; + /** @description Vertical position on the page in pixels. */ + pageY: number; + /** @description Viewport height in pixels. */ + viewportH: number; + /** @description Viewport width in pixels. */ + viewportW: number; + x: number; + y: number; + }[]; + scroll: { + buckets: { + depth: number; + /** @description Page height in pixels. */ + pageH: number; + /** @description Page width in pixels. */ + pageW: number; + sessions: number; + /** @description Viewport height in pixels. */ + viewportH: number; + /** @description Viewport width in pixels. */ + viewportW: number; + }[]; + /** @description Page height in pixels. */ + pageH: number; + /** @description Page width in pixels. */ + pageW: number; + totalSessions: number; + /** @description Viewport height in pixels. */ + viewportH: number; + /** @description Viewport width in pixels. */ + viewportW: number; + }; + snapshot: { + /** @description Unique identifier of the resource. */ + id: string; + /** @constant */ + kind: 'iframe'; + /** @description Page height in pixels. */ + pageH: number; + /** @description Page width in pixels. */ + pageW: number; + /** @description URL associated with the resource. */ + url: string; + /** @description Viewport height in pixels. */ + viewportH: number; + /** @description Viewport width in pixels. */ + viewportW: number; + }; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsiteJourneys: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + endStep?: string; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + startStep?: string; + steps: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Analytics results. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + /** @description Number of matching records. */ + count: number; + items: string[]; + }[]; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; getWebsiteMetrics: { parameters: { query: { @@ -16868,6 +19475,465 @@ export interface operations { }; }; }; + getWebsitePerformanceChart: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Numeric aggregation to calculate for the selected property. */ + metric?: 'lcp' | 'inp' | 'cls' | 'fcp' | 'ttfb'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Analytics results. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + chart: { + p50: number; + p75: number; + p95: number; + t: string; + }[]; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsitePerformanceMetrics: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Maximum number of rows to return. */ + limit?: number; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Numeric aggregation to calculate for the selected property. */ + metric?: 'lcp' | 'inp' | 'cls' | 'fcp' | 'ttfb'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Type of resource or analytics dimension to return. */ + type: 'path' | 'title' | 'device' | 'browser'; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Analytics results. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + /** @description Number of matching records. */ + count: number; + /** @description Display name of the resource. */ + name: string; + p50: number; + p75: number; + p95: number; + }[]; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; + getWebsitePerformanceStats: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Analytics results. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + cls: { + p50: number; + p75: number; + p95: number; + }; + /** @description Number of matching records. */ + count: number; + fcp: { + p50: number; + p75: number; + p95: number; + }; + inp: { + p50: number; + p75: number; + p95: number; + }; + lcp: { + p50: number; + p75: number; + p95: number; + }; + ttfb: { + p50: number; + p75: number; + p95: number; + }; + }; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; getWebsiteRecorderConfig: { parameters: { query?: never; @@ -17555,6 +20621,149 @@ export interface operations { }; }; }; + getWebsiteRetention: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The operation completed successfully. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + date: string; + day: number; + percentage: number; + returnVisitors: number; + /** @description Unique visitor counts for the selected period. */ + visitors: number; + }[]; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; getWebsiteRevenueChart: { parameters: { query: { @@ -21156,6 +24365,148 @@ export interface operations { }; }; }; + getWebsiteUtmMetrics: { + parameters: { + query: { + /** @description Browser used by the visitor. */ + browser?: string; + /** @description City of the visitor. */ + city?: string; + /** @description ID of a saved cohort used to filter visitors. */ + cohort?: string; + /** @description Country code of the visitor. */ + country?: string; + /** @description Device category used by the visitor. */ + device?: string; + /** @description Custom identifier assigned to the visitor. */ + distinctId?: string; + /** @description End of the date range as a Unix timestamp in milliseconds. */ + endAt: number; + /** @description Filter by custom event name. */ + event?: string; + /** @description Event type: 1 for a pageview or 2 for a custom event. */ + eventType?: number; + /** @description Set a non-empty value to exclude visits with only one pageview. */ + excludeBounce?: string; + /** @description Hostname on which the activity occurred. */ + hostname?: string; + /** @description Preferred language reported by the visitor browser. */ + language?: string; + /** @description Whether records must match all filters or any filter. */ + match?: 'all' | 'any'; + /** @description Operating system used by the visitor. */ + os?: string; + /** @description Filter by page URL path. */ + path?: string; + /** @description Filter by page URL query string. */ + query?: string; + /** @description Filter by referring URL. */ + referrer?: string; + /** @description Region or subdivision of the visitor. */ + region?: string; + /** @description ID of a saved segment used to filter results. */ + segment?: string; + /** @description Start of the date range as a Unix timestamp in milliseconds. */ + startAt: number; + /** @description Tag attached to the tracked activity. */ + tag?: string; + /** @description IANA time zone used to interpret dates and group results, for example America/New_York. */ + timezone?: string; + /** @description Filter by page title. */ + title?: string; + /** @description Type of resource or analytics dimension to return. */ + type: 'utm_source' | 'utm_medium' | 'utm_campaign' | 'utm_term' | 'utm_content'; + /** @description Time interval used to group results: minute, hour, day, month, or year. */ + unit?: string; + /** @description UTM campaign name. */ + utmCampaign?: string; + /** @description UTM campaign content. */ + utmContent?: string; + /** @description UTM campaign medium. */ + utmMedium?: string; + /** @description UTM campaign source. */ + utmSource?: string; + /** @description UTM campaign search term. */ + utmTerm?: string; + }; + header?: never; + path: { + /** @description ID of the website. */ + websiteId: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Analytics results. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + utm: string; + /** @description Pageview counts for the selected period. */ + views: number; + }[]; + }; + }; + /** @description Bad request. */ + 400: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "bad-request", + * "message": "Bad request.", + * "status": 400 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Unauthorized. */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "unauthorized", + * "message": "Unauthorized.", + * "status": 401 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + /** @description Not found. */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + /** + * @example { + * "error": { + * "code": "not-found", + * "message": "Not found.", + * "status": 404 + * } + * } + */ + 'application/json': components['schemas']['ApiError']; + }; + }; + }; + }; getWebsiteValues: { parameters: { query: { diff --git a/packages/mcp/src/server.test.ts b/packages/mcp/src/server.test.ts index ce2d9f3d0..835764ad6 100644 --- a/packages/mcp/src/server.test.ts +++ b/packages/mcp/src/server.test.ts @@ -159,7 +159,7 @@ describe('createUmamiMcpServer', () => { return { body: [{ dataKey: 'plan', stringValue: 'pro' }] }; } - if (path === '/api/reports/funnel') { + if (path === `/api/websites/${WEBSITE_ID}/funnels/stats`) { return { body: [ { @@ -184,6 +184,25 @@ describe('createUmamiMcpServer', () => { }; } + if (path === `/api/websites/${WEBSITE_ID}/revenue/stats`) { + return { + body: { + sum: 100, + count: 2, + average: 50, + unique_count: 2, + arpu: 50, + comparison: { sum: 80 }, + }, + }; + } + if (path === `/api/websites/${WEBSITE_ID}/revenue/chart`) { + return { body: { chart: [{ t: '2024-01-01', sum: 100 }] } }; + } + if (path === `/api/websites/${WEBSITE_ID}/revenue/metrics`) { + return { body: [{ name: url.searchParams.get('type'), value: 100 }] }; + } + if (path.startsWith('/api/websites/')) { return { status: 401, @@ -379,7 +398,7 @@ describe('createUmamiMcpServer', () => { }); }); - test('run_funnel posts a typed report body', async () => { + test('run_funnel sends structured criteria with GET', async () => { const result = await harness.client.callTool({ name: 'run_funnel', arguments: { @@ -401,11 +420,43 @@ describe('createUmamiMcpServer', () => { ], }); - const body = JSON.parse(harness.calls[0].init?.body as string); + const { url, init } = harness.calls[0]; + expect(init?.method).toBe('GET'); + expect(init?.body).toBeUndefined(); + expect(url.pathname).toBe(`/api/websites/${WEBSITE_ID}/funnels/stats`); + expect(JSON.parse(url.searchParams.get('steps')!)).toHaveLength(2); + expect(url.searchParams.get('window')).toBe('60'); + expect(Number(url.searchParams.get('startAt'))).toBeGreaterThan(0); + }); - expect(body).toMatchObject({ websiteId: WEBSITE_ID, type: 'funnel' }); - expect(body.parameters.steps).toHaveLength(2); - expect(body.parameters.window).toBe(60); + test('get_revenue composes feature APIs without changing its tool output', async () => { + const result = await harness.client.callTool({ + name: 'get_revenue', + arguments: { + websiteId: WEBSITE_ID, + startAt: '2024-01-01', + endAt: '2024-01-31', + currency: 'eur', + filters: { browser: 'Chrome' }, + }, + }); + expect(result.isError).toBeFalsy(); + expect(result.structuredContent).toMatchObject({ + currency: 'EUR', + total: { sum: 100, comparison: { sum: 80 } }, + chart: [{ sum: 100 }], + byCountry: [{ name: 'country', value: 100 }], + byRegion: [{ name: 'region' }], + byReferrer: [{ name: 'referrer' }], + byChannel: [{ name: 'channel' }], + }); + expect(harness.calls).toHaveLength(6); + for (const { url, init } of harness.calls) { + expect(init?.method).toBe('GET'); + expect(url.pathname).toContain(`/websites/${WEBSITE_ID}/revenue/`); + expect(url.searchParams.get('currency')).toBe('EUR'); + expect(url.searchParams.get('startAt')).toBe(String(Date.parse('2024-01-01'))); + } }); test('maps unauthorized website access to a helpful error', async () => { diff --git a/packages/mcp/src/tools/reports.ts b/packages/mcp/src/tools/reports.ts index 1bba6bbbb..3d060d82f 100644 --- a/packages/mcp/src/tools/reports.ts +++ b/packages/mcp/src/tools/reports.ts @@ -1,17 +1,10 @@ import { z } from 'zod'; -import { dateRangeInput, parseDateRange, timeUnit, timezone, toReportDates } from '../lib/dates'; +import { dateRangeInput, parseDateRange, timeUnit, timezone } from '../lib/dates'; import { filtersSchema, toFilterParams } from '../lib/filters'; import { defineTool } from '../lib/tool'; const websiteId = z.string().uuid().describe('Website ID from list_websites.'); -function reportFilters( - range: { startAt: number; endAt: number }, - filters?: z.infer, -) { - return { startAt: range.startAt, endAt: range.endAt, ...toFilterParams(filters) }; -} - function isoRange(range: { startAt: number; endAt: number }) { return { startAt: new Date(range.startAt).toISOString(), @@ -57,15 +50,12 @@ export const runFunnel = defineTool({ }), async handler(input, { client }) { const range = parseDateRange(input); - const result = await client.runFunnelReport({ + const result = await client.getWebsiteFunnelStats({ websiteId: input.websiteId, - type: 'funnel', - filters: reportFilters(range, input.filters), - parameters: { - ...toReportDates(range), - window: input.windowMinutes ?? 60, - steps: input.steps, - }, + ...range, + ...toFilterParams(input.filters), + window: input.windowMinutes ?? 60, + steps: JSON.stringify(input.steps), }); return { @@ -112,16 +102,13 @@ export const runJourney = defineTool({ }), async handler(input, { client }) { const range = parseDateRange(input); - const result = await client.runJourneyReport({ + const result = await client.getWebsiteJourneys({ websiteId: input.websiteId, - type: 'journey', - filters: reportFilters(range, input.filters), - parameters: { - ...toReportDates(range), - steps: input.steps ?? 3, - startStep: input.startStep, - endStep: input.endStep, - }, + ...range, + ...toFilterParams(input.filters), + steps: input.steps ?? 3, + startStep: input.startStep, + endStep: input.endStep, }); return { @@ -153,11 +140,11 @@ export const runRetention = defineTool({ }), async handler(input, { client }) { const range = parseDateRange(input); - const result = await client.runRetentionReport({ + const result = await client.getWebsiteRetention({ websiteId: input.websiteId, - type: 'retention', - filters: reportFilters(range, input.filters), - parameters: { ...toReportDates(range), timezone: input.timezone }, + ...range, + ...toFilterParams(input.filters), + timezone: input.timezone, }); return { @@ -209,16 +196,13 @@ export const runAttribution = defineTool({ }), async handler(input, { client }) { const range = parseDateRange(input); - const result = (await client.runAttributionReport({ + const result = (await client.getWebsiteAttribution({ websiteId: input.websiteId, - type: 'attribution', - filters: reportFilters(range, input.filters), - parameters: { - ...toReportDates(range), - model: input.model ?? 'last-click', - type: input.conversionType, - step: input.conversion, - }, + ...range, + ...toFilterParams(input.filters), + model: input.model ?? 'last-click', + type: input.conversionType, + step: input.conversion, })) as Record; const list = (value: unknown) => @@ -262,17 +246,23 @@ export const getRevenue = defineTool({ }), async handler(input, { client }) { const range = parseDateRange(input); - const result = (await client.runRevenueReport({ + const params = { websiteId: input.websiteId, - type: 'revenue', - filters: reportFilters(range, input.filters), - parameters: { - ...toReportDates(range), - currency: (input.currency ?? 'USD').toUpperCase(), - unit: input.unit, - timezone: input.timezone, - }, - })) as Record; + ...range, + ...toFilterParams(input.filters), + currency: (input.currency ?? 'USD').toUpperCase(), + unit: input.unit, + timezone: input.timezone, + }; + const [total, chart, country, region, referrer, channel] = await Promise.all([ + client.getWebsiteRevenueStats(params), + client.getWebsiteRevenueChart(params), + client.getWebsiteRevenueMetrics({ ...params, type: 'country' }), + client.getWebsiteRevenueMetrics({ ...params, type: 'region' }), + client.getWebsiteRevenueMetrics({ ...params, type: 'referrer' }), + client.getWebsiteRevenueMetrics({ ...params, type: 'channel' }), + ]); + const result = { total, chart: chart.chart, country, region, referrer, channel }; return { websiteId: input.websiteId, diff --git a/src/app/api/websites/[websiteId]/attribution/contract.ts b/src/app/api/websites/[websiteId]/attribution/contract.ts new file mode 100644 index 000000000..086d30061 --- /dev/null +++ b/src/app/api/websites/[websiteId]/attribution/contract.ts @@ -0,0 +1,166 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { attributionQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/attribution', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteAttribution', + summary: 'Get website attribution', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }), query: attributionQuerySchema }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + referrer: { + type: 'array', + items: { + type: 'object', + properties: { + name: { + type: 'string', + }, + value: { + type: 'number', + }, + }, + required: ['name', 'value'], + }, + }, + paidAds: { + type: 'array', + items: { + type: 'object', + properties: { + name: { + type: 'string', + }, + value: { + type: 'number', + }, + }, + required: ['name', 'value'], + }, + }, + utm_source: { + type: 'array', + items: { + type: 'object', + properties: { + name: { + type: 'string', + }, + value: { + type: 'number', + }, + }, + required: ['name', 'value'], + }, + }, + utm_medium: { + type: 'array', + items: { + type: 'object', + properties: { + name: { + type: 'string', + }, + value: { + type: 'number', + }, + }, + required: ['name', 'value'], + }, + }, + utm_campaign: { + type: 'array', + items: { + type: 'object', + properties: { + name: { + type: 'string', + }, + value: { + type: 'number', + }, + }, + required: ['name', 'value'], + }, + }, + utm_content: { + type: 'array', + items: { + type: 'object', + properties: { + name: { + type: 'string', + }, + value: { + type: 'number', + }, + }, + required: ['name', 'value'], + }, + }, + utm_term: { + type: 'array', + items: { + type: 'object', + properties: { + name: { + type: 'string', + }, + value: { + type: 'number', + }, + }, + required: ['name', 'value'], + }, + }, + total: { + type: 'object', + properties: { + pageviews: { + type: 'number', + }, + visitors: { + type: 'number', + }, + visits: { + type: 'number', + }, + }, + required: ['pageviews', 'visitors', 'visits'], + }, + }, + required: [ + 'referrer', + 'paidAds', + 'utm_source', + 'utm_medium', + 'utm_campaign', + 'utm_content', + 'utm_term', + 'total', + ], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/breakdown/contract.ts b/src/app/api/websites/[websiteId]/breakdown/contract.ts new file mode 100644 index 000000000..7bd3aa5fa --- /dev/null +++ b/src/app/api/websites/[websiteId]/breakdown/contract.ts @@ -0,0 +1,65 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { breakdownQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/breakdown', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteBreakdown', + summary: 'Get website breakdown', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }), query: breakdownQuerySchema }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'array', + items: { + type: 'object', + properties: { + views: { + type: 'number', + }, + visitors: { + type: 'number', + }, + visits: { + type: 'number', + }, + bounces: { + type: 'number', + }, + totaltime: { + type: 'number', + }, + }, + required: ['views', 'visitors', 'visits', 'bounces', 'totaltime'], + additionalProperties: { + anyOf: [ + { + type: 'string', + }, + { + type: 'number', + }, + ], + }, + }, + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/funnels/[funnelId]/contract.ts b/src/app/api/websites/[websiteId]/funnels/[funnelId]/contract.ts new file mode 100644 index 000000000..f9781da1c --- /dev/null +++ b/src/app/api/websites/[websiteId]/funnels/[funnelId]/contract.ts @@ -0,0 +1,101 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { + badRequestResponse, + unauthorizedResponse, + notFoundResponse, + jsonResponse, + okSchema, +} from '@/openapi/schemas'; +import { funnelDefinitionSchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/funnels/{funnelId}', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteFunnel', + summary: 'Get website funnel', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid(), funnelId: z.uuid() }) }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + ok: { + const: true, + }, + }, + required: ['ok'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), + defineOperation({ + method: 'post', + path: '/api/websites/{websiteId}/funnels/{funnelId}', + audience: 'public', + auth: 'bearer', + operation: { + operationId: 'updateWebsiteFunnel', + summary: 'Update website funnel', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid(), funnelId: z.uuid() }) }, + requestBody: { + required: true, + content: { 'application/json': { schema: funnelDefinitionSchema } }, + }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + ok: { + const: true, + }, + }, + required: ['ok'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), + defineOperation({ + method: 'delete', + path: '/api/websites/{websiteId}/funnels/{funnelId}', + audience: 'public', + auth: 'bearer', + operation: { + operationId: 'deleteWebsiteFunnel', + summary: 'Delete website funnel', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid(), funnelId: z.uuid() }) }, + responses: { + '200': jsonResponse(okSchema, 'Deleted successfully.'), + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/funnels/[funnelId]/stats/contract.ts b/src/app/api/websites/[websiteId]/funnels/[funnelId]/stats/contract.ts new file mode 100644 index 000000000..7fd69f236 --- /dev/null +++ b/src/app/api/websites/[websiteId]/funnels/[funnelId]/stats/contract.ts @@ -0,0 +1,90 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { savedStatsQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/funnels/{funnelId}/stats', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteSavedFunnelStats', + summary: 'Get website saved funnel stats', + tags: ['Websites'], + requestParams: { + path: z.object({ websiteId: z.uuid(), funnelId: z.uuid() }), + query: savedStatsQuerySchema, + }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'array', + items: { + type: 'object', + properties: { + visitors: { + type: 'number', + }, + previous: { + type: 'number', + }, + dropped: { + type: 'number', + }, + dropoff: { + type: 'number', + }, + remaining: { + type: 'number', + }, + type: { + type: 'string', + }, + value: { + type: 'string', + }, + filters: { + type: 'array', + items: { + type: 'object', + properties: { + property: { + type: 'string', + }, + operator: { + type: 'string', + }, + value: { + type: 'string', + }, + }, + required: ['property', 'operator', 'value'], + }, + }, + }, + required: [ + 'visitors', + 'previous', + 'dropped', + 'dropoff', + 'remaining', + 'type', + 'value', + ], + }, + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/funnels/contract.ts b/src/app/api/websites/[websiteId]/funnels/contract.ts new file mode 100644 index 000000000..a800b066b --- /dev/null +++ b/src/app/api/websites/[websiteId]/funnels/contract.ts @@ -0,0 +1,216 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { definitionListSchema, funnelDefinitionSchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/funnels', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteFunnels', + summary: 'Get website funnels', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }), query: definitionListSchema }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + data: { + type: 'array', + items: { + allOf: [ + { + type: 'object', + properties: { + id: { + type: 'string', + }, + userId: { + type: 'string', + }, + createdAt: { + type: 'string', + format: 'date-time', + }, + updatedAt: { + type: 'string', + format: 'date-time', + }, + name: { + type: 'string', + }, + type: { + type: 'string', + }, + description: { + type: 'string', + }, + parameters: { + anyOf: [ + { + type: 'string', + }, + { + type: 'number', + }, + { + const: false, + }, + { + const: true, + }, + { + type: 'object', + properties: {}, + additionalProperties: { + anyOf: [ + { + type: 'string', + }, + { + type: 'number', + }, + { + const: false, + }, + { + const: true, + }, + {}, + { + type: 'object', + properties: { + length: { + type: 'number', + }, + }, + required: ['length'], + }, + ], + }, + }, + { + type: 'object', + properties: { + length: { + type: 'number', + }, + }, + required: ['length'], + }, + ], + }, + websiteId: { + type: 'string', + }, + }, + required: [ + 'id', + 'userId', + 'createdAt', + 'updatedAt', + 'name', + 'type', + 'description', + 'parameters', + 'websiteId', + ], + }, + { + type: 'object', + properties: { + website: { + type: 'object', + properties: { + domain: { + type: 'string', + }, + userId: { + type: 'string', + }, + }, + required: ['domain', 'userId'], + }, + }, + }, + ], + }, + }, + count: { + type: 'number', + }, + page: { + type: 'number', + }, + pageSize: { + type: 'number', + }, + orderBy: { + type: 'string', + }, + sortDescending: { + type: 'boolean', + }, + search: { + type: 'string', + }, + isCapped: { + type: 'boolean', + }, + }, + required: ['data', 'count', 'page', 'pageSize'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), + defineOperation({ + method: 'post', + path: '/api/websites/{websiteId}/funnels', + audience: 'public', + auth: 'bearer', + operation: { + operationId: 'createWebsiteFunnel', + summary: 'Create website funnel', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }) }, + requestBody: { + required: true, + content: { 'application/json': { schema: funnelDefinitionSchema } }, + }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + ok: { + const: true, + }, + }, + required: ['ok'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/funnels/stats/contract.ts b/src/app/api/websites/[websiteId]/funnels/stats/contract.ts new file mode 100644 index 000000000..afdfc6ae9 --- /dev/null +++ b/src/app/api/websites/[websiteId]/funnels/stats/contract.ts @@ -0,0 +1,87 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { funnelQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/funnels/stats', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteFunnelStats', + summary: 'Get website funnel stats', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }), query: funnelQuerySchema }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'array', + items: { + type: 'object', + properties: { + visitors: { + type: 'number', + }, + previous: { + type: 'number', + }, + dropped: { + type: 'number', + }, + dropoff: { + type: 'number', + }, + remaining: { + type: 'number', + }, + type: { + type: 'string', + }, + value: { + type: 'string', + }, + filters: { + type: 'array', + items: { + type: 'object', + properties: { + property: { + type: 'string', + }, + operator: { + type: 'string', + }, + value: { + type: 'string', + }, + }, + required: ['property', 'operator', 'value'], + }, + }, + }, + required: [ + 'visitors', + 'previous', + 'dropped', + 'dropoff', + 'remaining', + 'type', + 'value', + ], + }, + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/goals/[goalId]/contract.ts b/src/app/api/websites/[websiteId]/goals/[goalId]/contract.ts new file mode 100644 index 000000000..60d270d10 --- /dev/null +++ b/src/app/api/websites/[websiteId]/goals/[goalId]/contract.ts @@ -0,0 +1,101 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { + badRequestResponse, + unauthorizedResponse, + notFoundResponse, + jsonResponse, + okSchema, +} from '@/openapi/schemas'; +import { goalDefinitionSchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/goals/{goalId}', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteGoal', + summary: 'Get website goal', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid(), goalId: z.uuid() }) }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + ok: { + const: true, + }, + }, + required: ['ok'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), + defineOperation({ + method: 'post', + path: '/api/websites/{websiteId}/goals/{goalId}', + audience: 'public', + auth: 'bearer', + operation: { + operationId: 'updateWebsiteGoal', + summary: 'Update website goal', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid(), goalId: z.uuid() }) }, + requestBody: { + required: true, + content: { 'application/json': { schema: goalDefinitionSchema } }, + }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + ok: { + const: true, + }, + }, + required: ['ok'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), + defineOperation({ + method: 'delete', + path: '/api/websites/{websiteId}/goals/{goalId}', + audience: 'public', + auth: 'bearer', + operation: { + operationId: 'deleteWebsiteGoal', + summary: 'Delete website goal', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid(), goalId: z.uuid() }) }, + responses: { + '200': jsonResponse(okSchema, 'Deleted successfully.'), + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/goals/[goalId]/stats/contract.ts b/src/app/api/websites/[websiteId]/goals/[goalId]/stats/contract.ts new file mode 100644 index 000000000..d9a5e45e8 --- /dev/null +++ b/src/app/api/websites/[websiteId]/goals/[goalId]/stats/contract.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { savedStatsQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/goals/{goalId}/stats', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteSavedGoalStats', + summary: 'Get website saved goal stats', + tags: ['Websites'], + requestParams: { + path: z.object({ websiteId: z.uuid(), goalId: z.uuid() }), + query: savedStatsQuerySchema, + }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + num: { + type: 'number', + }, + total: { + type: 'number', + }, + }, + required: ['num', 'total'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/goals/contract.ts b/src/app/api/websites/[websiteId]/goals/contract.ts new file mode 100644 index 000000000..6ada7aaa4 --- /dev/null +++ b/src/app/api/websites/[websiteId]/goals/contract.ts @@ -0,0 +1,216 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { definitionListSchema, goalDefinitionSchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/goals', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteGoals', + summary: 'Get website goals', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }), query: definitionListSchema }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + data: { + type: 'array', + items: { + allOf: [ + { + type: 'object', + properties: { + id: { + type: 'string', + }, + userId: { + type: 'string', + }, + createdAt: { + type: 'string', + format: 'date-time', + }, + updatedAt: { + type: 'string', + format: 'date-time', + }, + name: { + type: 'string', + }, + type: { + type: 'string', + }, + description: { + type: 'string', + }, + parameters: { + anyOf: [ + { + type: 'string', + }, + { + type: 'number', + }, + { + const: false, + }, + { + const: true, + }, + { + type: 'object', + properties: {}, + additionalProperties: { + anyOf: [ + { + type: 'string', + }, + { + type: 'number', + }, + { + const: false, + }, + { + const: true, + }, + {}, + { + type: 'object', + properties: { + length: { + type: 'number', + }, + }, + required: ['length'], + }, + ], + }, + }, + { + type: 'object', + properties: { + length: { + type: 'number', + }, + }, + required: ['length'], + }, + ], + }, + websiteId: { + type: 'string', + }, + }, + required: [ + 'id', + 'userId', + 'createdAt', + 'updatedAt', + 'name', + 'type', + 'description', + 'parameters', + 'websiteId', + ], + }, + { + type: 'object', + properties: { + website: { + type: 'object', + properties: { + domain: { + type: 'string', + }, + userId: { + type: 'string', + }, + }, + required: ['domain', 'userId'], + }, + }, + }, + ], + }, + }, + count: { + type: 'number', + }, + page: { + type: 'number', + }, + pageSize: { + type: 'number', + }, + orderBy: { + type: 'string', + }, + sortDescending: { + type: 'boolean', + }, + search: { + type: 'string', + }, + isCapped: { + type: 'boolean', + }, + }, + required: ['data', 'count', 'page', 'pageSize'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), + defineOperation({ + method: 'post', + path: '/api/websites/{websiteId}/goals', + audience: 'public', + auth: 'bearer', + operation: { + operationId: 'createWebsiteGoal', + summary: 'Create website goal', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }) }, + requestBody: { + required: true, + content: { 'application/json': { schema: goalDefinitionSchema } }, + }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + ok: { + const: true, + }, + }, + required: ['ok'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/goals/stats/contract.ts b/src/app/api/websites/[websiteId]/goals/stats/contract.ts new file mode 100644 index 000000000..95e9065a3 --- /dev/null +++ b/src/app/api/websites/[websiteId]/goals/stats/contract.ts @@ -0,0 +1,43 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { goalQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/goals/stats', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteGoalStats', + summary: 'Get website goal stats', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }), query: goalQuerySchema }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + num: { + type: 'number', + }, + total: { + type: 'number', + }, + }, + required: ['num', 'total'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/heatmaps/contract.ts b/src/app/api/websites/[websiteId]/heatmaps/contract.ts new file mode 100644 index 000000000..de82416c7 --- /dev/null +++ b/src/app/api/websites/[websiteId]/heatmaps/contract.ts @@ -0,0 +1,200 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { heatmapQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/heatmaps', + audience: 'public', + auth: 'bearer', + operation: { + operationId: 'getWebsiteHeatmaps', + summary: 'Get website heatmaps', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }), query: heatmapQuerySchema }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + mode: { + anyOf: [ + { + const: 'click', + }, + { + const: 'scroll', + }, + ], + }, + pages: { + type: 'array', + items: { + type: 'object', + properties: { + urlPath: { + type: 'string', + }, + count: { + type: 'number', + }, + sessions: { + type: 'number', + }, + }, + required: ['urlPath', 'count', 'sessions'], + }, + }, + points: { + type: 'array', + items: { + type: 'object', + properties: { + x: { + type: 'number', + }, + y: { + type: 'number', + }, + pageX: { + type: 'number', + }, + pageY: { + type: 'number', + }, + pageW: { + type: 'number', + }, + pageH: { + type: 'number', + }, + viewportW: { + type: 'number', + }, + viewportH: { + type: 'number', + }, + count: { + type: 'number', + }, + }, + required: [ + 'x', + 'y', + 'pageX', + 'pageY', + 'pageW', + 'pageH', + 'viewportW', + 'viewportH', + 'count', + ], + }, + }, + snapshot: { + type: 'object', + properties: { + kind: { + const: 'iframe', + }, + id: { + type: 'string', + }, + url: { + type: 'string', + }, + pageW: { + type: 'number', + }, + pageH: { + type: 'number', + }, + viewportW: { + type: 'number', + }, + viewportH: { + type: 'number', + }, + }, + required: ['kind', 'id', 'url', 'pageW', 'pageH', 'viewportW', 'viewportH'], + }, + scroll: { + type: 'object', + properties: { + buckets: { + type: 'array', + items: { + type: 'object', + properties: { + depth: { + type: 'number', + }, + sessions: { + type: 'number', + }, + pageW: { + type: 'number', + }, + pageH: { + type: 'number', + }, + viewportW: { + type: 'number', + }, + viewportH: { + type: 'number', + }, + }, + required: [ + 'depth', + 'sessions', + 'pageW', + 'pageH', + 'viewportW', + 'viewportH', + ], + }, + }, + totalSessions: { + type: 'number', + }, + pageW: { + type: 'number', + }, + pageH: { + type: 'number', + }, + viewportW: { + type: 'number', + }, + viewportH: { + type: 'number', + }, + }, + required: [ + 'buckets', + 'totalSessions', + 'pageW', + 'pageH', + 'viewportW', + 'viewportH', + ], + }, + }, + required: ['mode', 'pages', 'points', 'snapshot', 'scroll'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/journeys/contract.ts b/src/app/api/websites/[websiteId]/journeys/contract.ts new file mode 100644 index 000000000..e6aea2268 --- /dev/null +++ b/src/app/api/websites/[websiteId]/journeys/contract.ts @@ -0,0 +1,49 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { journeyQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/journeys', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteJourneys', + summary: 'Get website journeys', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }), query: journeyQuerySchema }, + responses: { + '200': { + description: 'Analytics results.', + content: { + 'application/json': { + schema: { + type: 'array', + items: { + type: 'object', + properties: { + items: { + type: 'array', + items: { + type: 'string', + }, + }, + count: { + type: 'number', + }, + }, + required: ['items', 'count'], + }, + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/performance/chart/contract.ts b/src/app/api/websites/[websiteId]/performance/chart/contract.ts new file mode 100644 index 000000000..c8c326243 --- /dev/null +++ b/src/app/api/websites/[websiteId]/performance/chart/contract.ts @@ -0,0 +1,61 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { performanceChartQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/performance/chart', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsitePerformanceChart', + summary: 'Get website performance chart', + tags: ['Websites'], + requestParams: { + path: z.object({ websiteId: z.uuid() }), + query: performanceChartQuerySchema, + }, + responses: { + '200': { + description: 'Analytics results.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + chart: { + type: 'array', + items: { + type: 'object', + properties: { + t: { + type: 'string', + }, + p50: { + type: 'number', + }, + p75: { + type: 'number', + }, + p95: { + type: 'number', + }, + }, + required: ['t', 'p50', 'p75', 'p95'], + }, + }, + }, + required: ['chart'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/performance/metrics/contract.ts b/src/app/api/websites/[websiteId]/performance/metrics/contract.ts new file mode 100644 index 000000000..a96099131 --- /dev/null +++ b/src/app/api/websites/[websiteId]/performance/metrics/contract.ts @@ -0,0 +1,58 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { performanceMetricsQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/performance/metrics', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsitePerformanceMetrics', + summary: 'Get website performance metrics', + tags: ['Websites'], + requestParams: { + path: z.object({ websiteId: z.uuid() }), + query: performanceMetricsQuerySchema, + }, + responses: { + '200': { + description: 'Analytics results.', + content: { + 'application/json': { + schema: { + type: 'array', + items: { + type: 'object', + properties: { + name: { + type: 'string', + }, + p50: { + type: 'number', + }, + p75: { + type: 'number', + }, + p95: { + type: 'number', + }, + count: { + type: 'number', + }, + }, + required: ['name', 'p50', 'p75', 'p95', 'count'], + }, + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/performance/stats/contract.ts b/src/app/api/websites/[websiteId]/performance/stats/contract.ts new file mode 100644 index 000000000..8906d0f78 --- /dev/null +++ b/src/app/api/websites/[websiteId]/performance/stats/contract.ts @@ -0,0 +1,118 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { performanceStatsQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/performance/stats', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsitePerformanceStats', + summary: 'Get website performance stats', + tags: ['Websites'], + requestParams: { + path: z.object({ websiteId: z.uuid() }), + query: performanceStatsQuerySchema, + }, + responses: { + '200': { + description: 'Analytics results.', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + lcp: { + type: 'object', + properties: { + p50: { + type: 'number', + }, + p75: { + type: 'number', + }, + p95: { + type: 'number', + }, + }, + required: ['p50', 'p75', 'p95'], + }, + inp: { + type: 'object', + properties: { + p50: { + type: 'number', + }, + p75: { + type: 'number', + }, + p95: { + type: 'number', + }, + }, + required: ['p50', 'p75', 'p95'], + }, + cls: { + type: 'object', + properties: { + p50: { + type: 'number', + }, + p75: { + type: 'number', + }, + p95: { + type: 'number', + }, + }, + required: ['p50', 'p75', 'p95'], + }, + fcp: { + type: 'object', + properties: { + p50: { + type: 'number', + }, + p75: { + type: 'number', + }, + p95: { + type: 'number', + }, + }, + required: ['p50', 'p75', 'p95'], + }, + ttfb: { + type: 'object', + properties: { + p50: { + type: 'number', + }, + p75: { + type: 'number', + }, + p95: { + type: 'number', + }, + }, + required: ['p50', 'p75', 'p95'], + }, + count: { + type: 'number', + }, + }, + required: ['lcp', 'inp', 'cls', 'fcp', 'ttfb', 'count'], + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/retention/contract.ts b/src/app/api/websites/[websiteId]/retention/contract.ts new file mode 100644 index 000000000..b9f39672e --- /dev/null +++ b/src/app/api/websites/[websiteId]/retention/contract.ts @@ -0,0 +1,55 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { retentionQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/retention', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteRetention', + summary: 'Get website retention', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }), query: retentionQuerySchema }, + responses: { + '200': { + description: 'The operation completed successfully.', + content: { + 'application/json': { + schema: { + type: 'array', + items: { + type: 'object', + properties: { + date: { + type: 'string', + }, + day: { + type: 'number', + }, + visitors: { + type: 'number', + }, + returnVisitors: { + type: 'number', + }, + percentage: { + type: 'number', + }, + }, + required: ['date', 'day', 'visitors', 'returnVisitors', 'percentage'], + }, + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/utm/metrics/contract.ts b/src/app/api/websites/[websiteId]/utm/metrics/contract.ts new file mode 100644 index 000000000..f7e8b05f2 --- /dev/null +++ b/src/app/api/websites/[websiteId]/utm/metrics/contract.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; +import { defineOperation } from '@/openapi/operation'; +import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas'; +import { utmMetricsQuerySchema } from '@/lib/analytics-schema'; + +export const operations = [ + defineOperation({ + method: 'get', + path: '/api/websites/{websiteId}/utm/metrics', + audience: 'public', + auth: 'bearer-or-share', + operation: { + operationId: 'getWebsiteUtmMetrics', + summary: 'Get website utm metrics', + tags: ['Websites'], + requestParams: { path: z.object({ websiteId: z.uuid() }), query: utmMetricsQuerySchema }, + responses: { + '200': { + description: 'Analytics results.', + content: { + 'application/json': { + schema: { + type: 'array', + items: { + type: 'object', + properties: { + utm: { + type: 'string', + }, + views: { + type: 'number', + }, + }, + required: ['utm', 'views'], + }, + }, + }, + }, + }, + '400': badRequestResponse, + '401': unauthorizedResponse, + '404': notFoundResponse, + }, + }, + }), +] as const; diff --git a/src/app/api/websites/[websiteId]/utm/metrics/route.ts b/src/app/api/websites/[websiteId]/utm/metrics/route.ts index 42571789c..dce1e49b3 100644 --- a/src/app/api/websites/[websiteId]/utm/metrics/route.ts +++ b/src/app/api/websites/[websiteId]/utm/metrics/route.ts @@ -13,5 +13,11 @@ export async function GET( const { websiteId } = await params; if (!(await canViewWebsiteSection(auth, websiteId, 'utm'))) return unauthorized(); const filters = await getQueryFilters(query, websiteId); - return json(await getUTM(websiteId, { startDate: filters.startDate, endDate: filters.endDate, column: query.type }, filters)); + return json( + await getUTM( + websiteId, + { startDate: filters.startDate, endDate: filters.endDate, column: query.type }, + filters, + ), + ); } diff --git a/src/lib/mcp/dispatch.ts b/src/lib/mcp/dispatch.ts index 880a4970d..1375a7056 100644 --- a/src/lib/mcp/dispatch.ts +++ b/src/lib/mcp/dispatch.ts @@ -119,36 +119,50 @@ export const MCP_DISPATCH_ROUTES: readonly DispatchRoute[] = [ load: () => import('@/app/api/websites/[websiteId]/sessions/[sessionId]/properties/route'), }, { - method: 'POST', - path: '/api/reports/attribution', - load: () => import('@/app/api/reports/attribution/route'), + method: 'GET', + path: '/api/websites/{websiteId}/attribution', + load: () => import('@/app/api/websites/[websiteId]/attribution/route'), }, { - method: 'POST', - path: '/api/reports/breakdown', - load: () => import('@/app/api/reports/breakdown/route'), + method: 'GET', + path: '/api/websites/{websiteId}/breakdown', + load: () => import('@/app/api/websites/[websiteId]/breakdown/route'), }, { - method: 'POST', - path: '/api/reports/funnel', - load: () => import('@/app/api/reports/funnel/route'), + method: 'GET', + path: '/api/websites/{websiteId}/funnels/stats', + load: () => import('@/app/api/websites/[websiteId]/funnels/stats/route'), }, { - method: 'POST', - path: '/api/reports/journey', - load: () => import('@/app/api/reports/journey/route'), + method: 'GET', + path: '/api/websites/{websiteId}/journeys', + load: () => import('@/app/api/websites/[websiteId]/journeys/route'), }, { - method: 'POST', - path: '/api/reports/retention', - load: () => import('@/app/api/reports/retention/route'), + method: 'GET', + path: '/api/websites/{websiteId}/retention', + load: () => import('@/app/api/websites/[websiteId]/retention/route'), }, { - method: 'POST', - path: '/api/reports/revenue', - load: () => import('@/app/api/reports/revenue/route'), + method: 'GET', + path: '/api/websites/{websiteId}/utm/metrics', + load: () => import('@/app/api/websites/[websiteId]/utm/metrics/route'), + }, + { + method: 'GET', + path: '/api/websites/{websiteId}/revenue/stats', + load: () => import('@/app/api/websites/[websiteId]/revenue/stats/route'), + }, + { + method: 'GET', + path: '/api/websites/{websiteId}/revenue/chart', + load: () => import('@/app/api/websites/[websiteId]/revenue/chart/route'), + }, + { + method: 'GET', + path: '/api/websites/{websiteId}/revenue/metrics', + load: () => import('@/app/api/websites/[websiteId]/revenue/metrics/route'), }, - { method: 'POST', path: '/api/reports/utm', load: () => import('@/app/api/reports/utm/route') }, ]; function escapeRegExp(value: string) {