/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as components from "../components/index.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * The type of event to retrieve analytics for. Defaults to `clicks`. */ export const Event = { Clicks: "clicks", Leads: "leads", Sales: "sales", Composite: "composite", } as const; /** * The type of event to retrieve analytics for. Defaults to `clicks`. */ export type Event = ClosedEnum; /** * The parameter to group the analytics data points by. Defaults to `count` if undefined. */ export const QueryParamGroupBy = { Count: "count", Timeseries: "timeseries", Continents: "continents", Regions: "regions", Countries: "countries", Cities: "cities", Devices: "devices", Browsers: "browsers", Os: "os", Trigger: "trigger", Triggers: "triggers", Referers: "referers", RefererUrls: "referer_urls", TopFolders: "top_folders", TopLinkTags: "top_link_tags", TopDomains: "top_domains", TopLinks: "top_links", TopUrls: "top_urls", TopBaseUrls: "top_base_urls", TopPartners: "top_partners", TopGroups: "top_groups", UtmSources: "utm_sources", UtmMediums: "utm_mediums", UtmCampaigns: "utm_campaigns", UtmTerms: "utm_terms", UtmContents: "utm_contents", } as const; /** * The parameter to group the analytics data points by. Defaults to `count` if undefined. */ export type QueryParamGroupBy = ClosedEnum; /** * The interval to retrieve analytics for. If undefined, defaults to 24h. */ export const Interval = { TwentyFourh: "24h", Sevend: "7d", Thirtyd: "30d", Ninetyd: "90d", Oney: "1y", Mtd: "mtd", Qtd: "qtd", Ytd: "ytd", All: "all", } as const; /** * The interval to retrieve analytics for. If undefined, defaults to 24h. */ export type Interval = ClosedEnum; /** * Filter sales by type: 'new' for first-time purchases, 'recurring' for repeat purchases. If undefined, returns both. */ export const SaleType = { New: "new", Recurring: "recurring", } as const; /** * Filter sales by type: 'new' for first-time purchases, 'recurring' for repeat purchases. If undefined, returns both. */ export type SaleType = ClosedEnum; export type RetrieveAnalyticsRequest = { /** * The type of event to retrieve analytics for. Defaults to `clicks`. */ event?: Event | undefined; /** * The parameter to group the analytics data points by. Defaults to `count` if undefined. */ groupBy?: QueryParamGroupBy | undefined; /** * The domain to filter analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `dub.co`, `dub.co,google.com`, `-spam.com`. */ domain?: string | undefined; /** * The slug of the short link to retrieve analytics for. Must be used along with the corresponding `domain` of the short link to fetch analytics for a specific short link. */ key?: string | undefined; /** * The unique ID of the link to retrieve analytics for.Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `link_123`, `link_123,link_456`, `-link_789`. */ linkId?: string | undefined; /** * The ID of the link in the your database. Must be prefixed with 'ext_' when passed as a query parameter. */ externalId?: string | undefined; /** * The ID of the tenant that created the link inside your system. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `tenant_123`, `tenant_123,tenant_456`, `-tenant_789`. */ tenantId?: string | undefined; /** * The tag ID to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `tag_123`, `tag_123,tag_456`, `-tag_789`. */ tagId?: string | undefined; /** * The folder ID to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `folder_123`, `folder_123,folder_456`, `-folder_789`. If not provided, return analytics for all links. */ folderId?: string | undefined; /** * The group ID to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `grp_123`, `grp_123,grp_456`, `-grp_789`. */ groupId?: string | undefined; /** * The ID of the partner to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `pn_123`, `pn_123,pn_456`, `-pn_789`. */ partnerId?: string | undefined; /** * The ID of the customer to retrieve analytics for. */ customerId?: string | undefined; /** * The interval to retrieve analytics for. If undefined, defaults to 24h. */ interval?: Interval | undefined; /** * The start date and time when to retrieve analytics from. If set, takes precedence over `interval`. */ start?: string | undefined; /** * The end date and time when to retrieve analytics from. If not provided, defaults to the current date. If set along with `start`, takes precedence over `interval`. */ end?: string | undefined; /** * The IANA time zone code for aligning timeseries granularity (e.g. America/New_York). Defaults to UTC. */ timezone?: string | undefined; /** * The country to retrieve analytics for. Must be passed as a 2-letter ISO 3166-1 country code (see https://d.to/geo). Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `US`, `US,BR,FR`, `-US`. */ country?: string | undefined; /** * The city to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `New York`, `New York,London`, `-New York`. */ city?: string | undefined; /** * The ISO 3166-2 region code to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `NY`, `NY,CA`, `-NY`. */ region?: string | undefined; /** * The continent to retrieve analytics for. Valid values: AF, AN, AS, EU, NA, OC, SA. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `NA`, `NA,EU`, `-AS`. */ continent?: string | undefined; /** * The device to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `Desktop`, `Mobile,Tablet`, `-Mobile`. */ device?: string | undefined; /** * The browser to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `Chrome`, `Chrome,Firefox,Safari`, `-IE`. */ browser?: string | undefined; /** * The OS to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `Windows`, `Mac,Windows,Linux`, `-Windows`. */ os?: string | undefined; /** * The trigger to retrieve analytics for. Valid values: qr, link, pageview. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `qr`, `qr,link`, `-qr`. If undefined, returns all trigger types. */ trigger?: string | undefined; /** * The referer hostname to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `google.com`, `google.com,twitter.com`, `-facebook.com`. */ referer?: string | undefined; /** * The full referer URL to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `https://google.com`, `https://google.com,https://twitter.com`, `-https://spam.com`. */ refererUrl?: string | undefined; /** * The destination URL to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `https://example.com`, `https://example.com,https://other.com`, `-https://spam.com`. */ url?: string | undefined; /** * The UTM source to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `google`, `google,twitter`, `-spam`. */ utmSource?: string | undefined; /** * The UTM medium to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `cpc`, `cpc,social`, `-email`. */ utmMedium?: string | undefined; /** * The UTM campaign to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). Examples: `summer_sale`, `summer_sale,winter_sale`, `-old_campaign`. */ utmCampaign?: string | undefined; /** * The UTM term to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). */ utmTerm?: string | undefined; /** * The UTM content to retrieve analytics for. Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). */ utmContent?: string | undefined; /** * Filter for root domains. If true, filter for domains only. If false, filter for links only. If undefined, return both. */ root?: boolean | undefined; /** * Filter sales by type: 'new' for first-time purchases, 'recurring' for repeat purchases. If undefined, returns both. */ saleType?: SaleType | undefined; /** * Search the events by a custom metadata value. Only available for lead and sale events. Examples: `metadata['key']:'value'` */ query?: string | undefined; /** * Deprecated: This is automatically inferred from your workspace's defaultProgramId. The ID of the program to retrieve analytics for. */ programId?: string | undefined; /** * Deprecated: Use `tagId` instead. The tag IDs to retrieve analytics for. */ tagIds?: string | undefined; /** * Deprecated: Use the `trigger` field instead. Filter for QR code scans. If true, filter for QR codes only. If false, filter for links only. If undefined, return both. */ qr?: boolean | undefined; }; /** * Analytics data */ export type RetrieveAnalyticsResponseBody = | components.AnalyticsCount | Array | Array | Array | Array | Array | Array | Array | Array | Array | Array | Array | Array | Array; /** @internal */ export const Event$outboundSchema: z.ZodNativeEnum = z.nativeEnum( Event, ); /** @internal */ export const QueryParamGroupBy$outboundSchema: z.ZodNativeEnum< typeof QueryParamGroupBy > = z.nativeEnum(QueryParamGroupBy); /** @internal */ export const Interval$outboundSchema: z.ZodNativeEnum = z .nativeEnum(Interval); /** @internal */ export const SaleType$outboundSchema: z.ZodNativeEnum = z .nativeEnum(SaleType); /** @internal */ export type RetrieveAnalyticsRequest$Outbound = { event: string; groupBy: string; domain?: string | undefined; key?: string | undefined; linkId?: string | undefined; externalId?: string | undefined; tenantId?: string | undefined; tagId?: string | undefined; folderId?: string | undefined; groupId?: string | undefined; partnerId?: string | undefined; customerId?: string | undefined; interval?: string | undefined; start?: string | undefined; end?: string | undefined; timezone: string; country?: string | undefined; city?: string | undefined; region?: string | undefined; continent?: string | undefined; device?: string | undefined; browser?: string | undefined; os?: string | undefined; trigger?: string | undefined; referer?: string | undefined; refererUrl?: string | undefined; url?: string | undefined; utm_source?: string | undefined; utm_medium?: string | undefined; utm_campaign?: string | undefined; utm_term?: string | undefined; utm_content?: string | undefined; root?: boolean | undefined; saleType?: string | undefined; query?: string | undefined; programId?: string | undefined; tagIds?: string | undefined; qr?: boolean | undefined; }; /** @internal */ export const RetrieveAnalyticsRequest$outboundSchema: z.ZodType< RetrieveAnalyticsRequest$Outbound, z.ZodTypeDef, RetrieveAnalyticsRequest > = z.object({ event: Event$outboundSchema.default("clicks"), groupBy: QueryParamGroupBy$outboundSchema.default("count"), domain: z.string().optional(), key: z.string().optional(), linkId: z.string().optional(), externalId: z.string().optional(), tenantId: z.string().optional(), tagId: z.string().optional(), folderId: z.string().optional(), groupId: z.string().optional(), partnerId: z.string().optional(), customerId: z.string().optional(), interval: Interval$outboundSchema.optional(), start: z.string().optional(), end: z.string().optional(), timezone: z.string().default("UTC"), country: z.string().optional(), city: z.string().optional(), region: z.string().optional(), continent: z.string().optional(), device: z.string().optional(), browser: z.string().optional(), os: z.string().optional(), trigger: z.string().optional(), referer: z.string().optional(), refererUrl: z.string().optional(), url: z.string().optional(), utmSource: z.string().optional(), utmMedium: z.string().optional(), utmCampaign: z.string().optional(), utmTerm: z.string().optional(), utmContent: z.string().optional(), root: z.boolean().optional(), saleType: SaleType$outboundSchema.optional(), query: z.string().optional(), programId: z.string().optional(), tagIds: z.string().optional(), qr: z.boolean().optional(), }).transform((v) => { return remap$(v, { utmSource: "utm_source", utmMedium: "utm_medium", utmCampaign: "utm_campaign", utmTerm: "utm_term", utmContent: "utm_content", }); }); export function retrieveAnalyticsRequestToJSON( retrieveAnalyticsRequest: RetrieveAnalyticsRequest, ): string { return JSON.stringify( RetrieveAnalyticsRequest$outboundSchema.parse(retrieveAnalyticsRequest), ); } /** @internal */ export const RetrieveAnalyticsResponseBody$inboundSchema: z.ZodType< RetrieveAnalyticsResponseBody, z.ZodTypeDef, unknown > = z.union([ components.AnalyticsCount$inboundSchema, z.array(components.AnalyticsTimeseries$inboundSchema), z.array(components.AnalyticsContinents$inboundSchema), z.array(components.AnalyticsCountries$inboundSchema), z.array(components.AnalyticsRegions$inboundSchema), z.array(components.AnalyticsCities$inboundSchema), z.array(components.AnalyticsDevices$inboundSchema), z.array(components.AnalyticsBrowsers$inboundSchema), z.array(components.AnalyticsOS$inboundSchema), z.array(components.AnalyticsTriggers$inboundSchema), z.array(components.AnalyticsReferers$inboundSchema), z.array(components.AnalyticsRefererUrls$inboundSchema), z.array(components.AnalyticsTopLinks$inboundSchema), z.array(components.AnalyticsTopUrls$inboundSchema), ]); export function retrieveAnalyticsResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => RetrieveAnalyticsResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'RetrieveAnalyticsResponseBody' from JSON`, ); }