import {z} from 'zod' export type GoogleAdsSearchads360V23CommonAdditionalApplicationInfo = {applicationId?: string | undefined, applicationInstance?: ('UNSPECIFIED' | 'UNKNOWN' | 'DEVELOPMENT_AND_TESTING' | 'PRODUCTION') | undefined}; export type GoogleAdsSearchads360V23ServicesBenchmarksSource = {industryVerticalId?: unknown | undefined}; export type GoogleAdsSearchads360V23CommonDateRange = {endDate?: string | undefined, startDate?: string | undefined}; export type GoogleAdsSearchads360V23CommonLocationInfo = {geoTargetConstant?: string | undefined}; export type GoogleAdsSearchads360V23ServicesProductFilterMarketingObjectiveList = {marketingObjectives?: (Array<'UNSPECIFIED' | 'UNKNOWN' | 'AWARENESS' | 'CONSIDERATION' | 'ACTION'>) | undefined}; export type GoogleAdsSearchads360V23ServicesProductFilterProductList = {productCodes?: Array | undefined}; export type GoogleAdsSearchads360V23ServicesProductFilter = {marketingObjectiveList?: GoogleAdsSearchads360V23ServicesProductFilterMarketingObjectiveList | undefined, productList?: GoogleAdsSearchads360V23ServicesProductFilterProductList | undefined}; export type GoogleAdsSearchads360V23ServicesGenerateBenchmarksMetricsRequest = {applicationInfo?: GoogleAdsSearchads360V23CommonAdditionalApplicationInfo | undefined, benchmarksSource?: GoogleAdsSearchads360V23ServicesBenchmarksSource | undefined, currencyCode?: string | undefined, customerBenchmarksGroup?: string | undefined, dateRange?: GoogleAdsSearchads360V23CommonDateRange | undefined, location?: GoogleAdsSearchads360V23CommonLocationInfo | undefined, productFilter?: GoogleAdsSearchads360V23ServicesProductFilter | undefined}; export type CreateApiV23CustomersCustomersIdGenerateBenchmarksMetricsArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesGenerateBenchmarksMetricsRequest}; export type CreateApiV23CustomersCustomersIdGenerateBenchmarksMetricsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleAdsSearchads360V23ServicesRateMetrics = z.object({activeViewViewability: z.number().optional(), averageActiveViewCpm: z.number().optional(), averageCpc: z.number().optional(), averageCpe: z.number().optional(), averageCpi: z.number().optional(), averageCpm: z.number().optional(), clickThroughRate: z.number().optional(), engagementRate: z.number().optional(), interactionRate: z.number().optional(), trueviewAverageCpv: z.number().optional(), trueviewViewRate: z.number().optional(), videoCompletionP100Rate: z.number().optional(), videoCompletionP25Rate: z.number().optional(), videoCompletionP50Rate: z.number().optional(), videoCompletionP75Rate: z.number().optional()}); export const googleAdsSearchads360V23ServicesMetrics = z.object({averageRateMetrics: googleAdsSearchads360V23ServicesRateMetrics.optional()}); export const googleAdsSearchads360V23ServicesGenerateBenchmarksMetricsResponse = z.object({averageBenchmarksMetrics: googleAdsSearchads360V23ServicesMetrics.optional(), customerMetrics: googleAdsSearchads360V23ServicesMetrics.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Returns YouTube advertisement metrics for the given client against industry benchmarks. List of thrown errors: [AuthenticationError]() [AuthorizationError]() [BenchmarksError]() [FieldError]() [HeaderError]() [InternalError]() [QuotaError]() [RangeError]() [RequestError]() * * POST /v23/customers/{customersId}:generateBenchmarksMetrics */ export const createApiV23CustomersCustomersIdGenerateBenchmarksMetrics = async (args: CreateApiV23CustomersCustomersIdGenerateBenchmarksMetricsArgs, options?: CreateApiV23CustomersCustomersIdGenerateBenchmarksMetricsOptions) => { const {baseUrl = "https://searchads360.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v23/customers/${encodeURIComponent(String(args.customersId))}:generateBenchmarksMetrics${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(googleAdsSearchads360V23ServicesGenerateBenchmarksMetricsResponse, await res.json()) };