import {z} from 'zod' export type GoogleAdsSearchads360V23CommonAgeRangeInfo = {type?: ('UNSPECIFIED' | 'UNKNOWN' | 'AGE_RANGE_18_24' | 'AGE_RANGE_25_34' | 'AGE_RANGE_35_44' | 'AGE_RANGE_45_54' | 'AGE_RANGE_55_64' | 'AGE_RANGE_65_UP' | 'AGE_RANGE_UNDETERMINED') | undefined}; export type GoogleAdsSearchads360V23CommonLocationInfo = {geoTargetConstant?: string | undefined}; export type GoogleAdsSearchads360V23CommonGenderInfo = {type?: ('UNSPECIFIED' | 'UNKNOWN' | 'MALE' | 'FEMALE' | 'UNDETERMINED') | undefined}; export type GoogleAdsSearchads360V23CommonIncomeRangeInfo = {type?: ('UNSPECIFIED' | 'UNKNOWN' | 'INCOME_RANGE_0_50' | 'INCOME_RANGE_50_60' | 'INCOME_RANGE_60_70' | 'INCOME_RANGE_70_80' | 'INCOME_RANGE_80_90' | 'INCOME_RANGE_90_UP' | 'INCOME_RANGE_UNDETERMINED') | undefined}; export type GoogleAdsSearchads360V23CommonAudienceInsightsLineup = {lineupId?: string | undefined}; export type GoogleAdsSearchads360V23CommonParentalStatusInfo = {type?: ('UNSPECIFIED' | 'UNKNOWN' | 'PARENT' | 'NOT_A_PARENT' | 'UNDETERMINED') | undefined}; export type GoogleAdsSearchads360V23CommonAudienceInsightsCategory = {categoryId?: string | undefined}; export type GoogleAdsSearchads360V23CommonDeviceInfo = {type?: ('UNSPECIFIED' | 'UNKNOWN' | 'MOBILE' | 'TABLET' | 'DESKTOP' | 'CONNECTED_TV' | 'OTHER') | undefined}; export type GoogleAdsSearchads360V23CommonAudienceInsightsEntity = {knowledgeGraphMachineId?: string | undefined}; export type GoogleAdsSearchads360V23CommonUserInterestInfo = {userInterestCategory?: string | undefined}; export type GoogleAdsSearchads360V23CommonUserListInfo = {userList?: string | undefined}; export type GoogleAdsSearchads360V23CommonYouTubeChannelInfo = {channelId?: string | undefined}; export type GoogleAdsSearchads360V23CommonYouTubeVideoInfo = {videoId?: string | undefined}; export type GoogleAdsSearchads360V23CommonAudienceInsightsAttribute = {ageRange?: GoogleAdsSearchads360V23CommonAgeRangeInfo | undefined, category?: GoogleAdsSearchads360V23CommonAudienceInsightsCategory | undefined, device?: GoogleAdsSearchads360V23CommonDeviceInfo | undefined, entity?: GoogleAdsSearchads360V23CommonAudienceInsightsEntity | undefined, gender?: GoogleAdsSearchads360V23CommonGenderInfo | undefined, incomeRange?: GoogleAdsSearchads360V23CommonIncomeRangeInfo | undefined, lineup?: GoogleAdsSearchads360V23CommonAudienceInsightsLineup | undefined, location?: GoogleAdsSearchads360V23CommonLocationInfo | undefined, parentalStatus?: GoogleAdsSearchads360V23CommonParentalStatusInfo | undefined, userInterest?: GoogleAdsSearchads360V23CommonUserInterestInfo | undefined, userList?: GoogleAdsSearchads360V23CommonUserListInfo | undefined, youtubeChannel?: GoogleAdsSearchads360V23CommonYouTubeChannelInfo | undefined, youtubeVideo?: GoogleAdsSearchads360V23CommonYouTubeVideoInfo | undefined}; export type GoogleAdsSearchads360V23ServicesInsightsAudienceAttributeGroup = {attributes?: Array | undefined}; export type GoogleAdsSearchads360V23ServicesInsightsAudience = {ageRanges?: Array | undefined, countryLocations?: Array | undefined, gender?: GoogleAdsSearchads360V23CommonGenderInfo | undefined, incomeRanges?: Array | undefined, lineups?: Array | undefined, parentalStatus?: GoogleAdsSearchads360V23CommonParentalStatusInfo | undefined, subCountryLocations?: Array | undefined, topicAudienceCombinations?: Array | undefined, userList?: GoogleAdsSearchads360V23CommonUserListInfo | undefined}; export type GoogleAdsSearchads360V23CommonAdditionalApplicationInfo = {applicationId?: string | undefined, applicationInstance?: ('UNSPECIFIED' | 'UNKNOWN' | 'DEVELOPMENT_AND_TESTING' | 'PRODUCTION') | undefined}; export type GoogleAdsSearchads360V23ServicesGenerateTargetingSuggestionMetricsRequest = {audiences?: Array | undefined, customerInsightsGroup?: string | undefined, insightsApplicationInfo?: GoogleAdsSearchads360V23CommonAdditionalApplicationInfo | undefined}; export type CreateApiV23CustomersCustomersIdGenerateTargetingSuggestionMetricsArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesGenerateTargetingSuggestionMetricsRequest}; export type CreateApiV23CustomersCustomersIdGenerateTargetingSuggestionMetricsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleAdsSearchads360V23CommonAgeRangeInfo = z.object({type: z.enum(["UNSPECIFIED", "UNKNOWN", "AGE_RANGE_18_24", "AGE_RANGE_25_34", "AGE_RANGE_35_44", "AGE_RANGE_45_54", "AGE_RANGE_55_64", "AGE_RANGE_65_UP", "AGE_RANGE_UNDETERMINED"]).optional()}); export const googleAdsSearchads360V23CommonGenderInfo = z.object({type: z.enum(["UNSPECIFIED", "UNKNOWN", "MALE", "FEMALE", "UNDETERMINED"]).optional()}); export const googleAdsSearchads360V23CommonAudienceInsightsCategory = z.object({categoryId: z.string().optional()}); export const googleAdsSearchads360V23CommonDeviceInfo = z.object({type: z.enum(["UNSPECIFIED", "UNKNOWN", "MOBILE", "TABLET", "DESKTOP", "CONNECTED_TV", "OTHER"]).optional()}); export const googleAdsSearchads360V23CommonAudienceInsightsEntity = z.object({knowledgeGraphMachineId: z.string().optional()}); export const googleAdsSearchads360V23CommonIncomeRangeInfo = z.object({type: z.enum(["UNSPECIFIED", "UNKNOWN", "INCOME_RANGE_0_50", "INCOME_RANGE_50_60", "INCOME_RANGE_60_70", "INCOME_RANGE_70_80", "INCOME_RANGE_80_90", "INCOME_RANGE_90_UP", "INCOME_RANGE_UNDETERMINED"]).optional()}); export const googleAdsSearchads360V23CommonAudienceInsightsLineup = z.object({lineupId: z.string().optional()}); export const googleAdsSearchads360V23CommonLocationInfo = z.object({geoTargetConstant: z.string().optional()}); export const googleAdsSearchads360V23CommonParentalStatusInfo = z.object({type: z.enum(["UNSPECIFIED", "UNKNOWN", "PARENT", "NOT_A_PARENT", "UNDETERMINED"]).optional()}); export const googleAdsSearchads360V23CommonUserInterestInfo = z.object({userInterestCategory: z.string().optional()}); export const googleAdsSearchads360V23CommonUserListInfo = z.object({userList: z.string().optional()}); export const googleAdsSearchads360V23CommonYouTubeChannelInfo = z.object({channelId: z.string().optional()}); export const googleAdsSearchads360V23CommonYouTubeVideoInfo = z.object({videoId: z.string().optional()}); export const googleAdsSearchads360V23CommonAudienceInsightsAttribute = z.object({ageRange: googleAdsSearchads360V23CommonAgeRangeInfo.optional(), category: googleAdsSearchads360V23CommonAudienceInsightsCategory.optional(), device: googleAdsSearchads360V23CommonDeviceInfo.optional(), entity: googleAdsSearchads360V23CommonAudienceInsightsEntity.optional(), gender: googleAdsSearchads360V23CommonGenderInfo.optional(), incomeRange: googleAdsSearchads360V23CommonIncomeRangeInfo.optional(), lineup: googleAdsSearchads360V23CommonAudienceInsightsLineup.optional(), location: googleAdsSearchads360V23CommonLocationInfo.optional(), parentalStatus: googleAdsSearchads360V23CommonParentalStatusInfo.optional(), userInterest: googleAdsSearchads360V23CommonUserInterestInfo.optional(), userList: googleAdsSearchads360V23CommonUserListInfo.optional(), youtubeChannel: googleAdsSearchads360V23CommonYouTubeChannelInfo.optional(), youtubeVideo: googleAdsSearchads360V23CommonYouTubeVideoInfo.optional()}); export const googleAdsSearchads360V23CommonKnowledgeGraphAttributeMetadata = z.object({entityCapabilities: z.array(z.enum(["UNSPECIFIED", "UNKNOWN", "CONTENT_TRENDING_INSIGHTS", "CREATOR_ATTRIBUTE"])).optional(), relatedCategories: z.array(z.lazy(() => googleAdsSearchads360V23CommonAudienceInsightsAttributeMetadata)).optional()}); export const googleAdsSearchads360V23CommonYouTubeChannelAttributeMetadata = z.object({subscriberCount: z.string().optional()}); export const googleAdsSearchads360V23CommonLineupAttributeMetadataSampleChannel = z.object({displayName: z.string().optional(), youtubeChannel: googleAdsSearchads360V23CommonYouTubeChannelInfo.optional(), youtubeChannelMetadata: googleAdsSearchads360V23CommonYouTubeChannelAttributeMetadata.optional()}); export const googleAdsSearchads360V23CommonLineupAttributeMetadata = z.object({channelCountLowerBound: z.string().optional(), channelCountUpperBound: z.string().optional(), inventoryCountry: googleAdsSearchads360V23CommonLocationInfo.optional(), medianMonthlyInventory: z.string().optional(), sampleChannels: z.array(googleAdsSearchads360V23CommonLineupAttributeMetadataSampleChannel).optional()}); export const googleAdsSearchads360V23CommonLocationAttributeMetadata = z.object({countryLocation: googleAdsSearchads360V23CommonLocationInfo.optional()}); export const googleAdsSearchads360V23CommonUserInterestAttributeMetadata = z.object({userInterestDescription: z.string().optional()}); export const googleAdsSearchads360V23CommonUserListAttributeMetadata = z.object({userListType: z.enum(["UNSPECIFIED", "UNKNOWN", "REMARKETING", "LOGICAL", "EXTERNAL_REMARKETING", "RULE_BASED", "SIMILAR", "CRM_BASED", "LOOKALIKE"]).optional()}); export const googleAdsSearchads360V23CommonYouTubeVideoAttributeMetadata = z.object({commentsCount: z.string().optional(), likesCount: z.string().optional(), publishDate: z.string().optional(), thumbnailUrl: z.string().optional(), videoProperties: z.array(z.enum(["UNSPECIFIED", "UNKNOWN", "LIVE_STREAM", "SHORTS"])).optional(), videoUrl: z.string().optional(), viewsCount: z.string().optional()}); export const googleAdsSearchads360V23CommonAudienceInsightsAttributeMetadata: z.ZodType = z.object({attribute: googleAdsSearchads360V23CommonAudienceInsightsAttribute.optional(), dimension: z.enum(["UNSPECIFIED", "UNKNOWN", "CATEGORY", "KNOWLEDGE_GRAPH", "GEO_TARGET_COUNTRY", "SUB_COUNTRY_LOCATION", "YOUTUBE_CHANNEL", "AFFINITY_USER_INTEREST", "IN_MARKET_USER_INTEREST", "PARENTAL_STATUS", "INCOME_RANGE", "AGE_RANGE", "GENDER", "YOUTUBE_VIDEO", "DEVICE", "YOUTUBE_LINEUP", "USER_LIST", "LIFE_EVENT_USER_INTEREST"]).optional(), displayInfo: z.string().optional(), displayName: z.string().optional(), knowledgeGraphAttributeMetadata: googleAdsSearchads360V23CommonKnowledgeGraphAttributeMetadata.optional(), lineupAttributeMetadata: googleAdsSearchads360V23CommonLineupAttributeMetadata.optional(), locationAttributeMetadata: googleAdsSearchads360V23CommonLocationAttributeMetadata.optional(), potentialYoutubeReach: z.string().optional(), subscriberShare: z.number().optional(), userInterestAttributeMetadata: googleAdsSearchads360V23CommonUserInterestAttributeMetadata.optional(), userListAttributeMetadata: googleAdsSearchads360V23CommonUserListAttributeMetadata.optional(), viewerShare: z.number().optional(), youtubeChannelMetadata: googleAdsSearchads360V23CommonYouTubeChannelAttributeMetadata.optional(), youtubeVideoMetadata: googleAdsSearchads360V23CommonYouTubeVideoAttributeMetadata.optional()}); export const googleAdsSearchads360V23CommonAudienceInsightsAttributeMetadataGroup = z.object({attributes: z.array(googleAdsSearchads360V23CommonAudienceInsightsAttributeMetadata).optional()}); export const googleAdsSearchads360V23ServicesTargetingSuggestionMetrics = z.object({ageRanges: z.array(googleAdsSearchads360V23CommonAgeRangeInfo).optional(), coverage: z.number().optional(), gender: googleAdsSearchads360V23CommonGenderInfo.optional(), index: z.number().optional(), locations: z.array(googleAdsSearchads360V23CommonAudienceInsightsAttributeMetadata).optional(), parentalStatus: googleAdsSearchads360V23CommonParentalStatusInfo.optional(), potentialYoutubeReach: z.string().optional(), userInterests: z.array(googleAdsSearchads360V23CommonAudienceInsightsAttributeMetadataGroup).optional()}); export const googleAdsSearchads360V23ServicesGenerateTargetingSuggestionMetricsResponse = z.object({suggestions: z.array(googleAdsSearchads360V23ServicesTargetingSuggestionMetrics).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 potential reach metrics for targetable audiences. This method helps answer questions like "How many Men aged 18+ interested in Camping can be reached on YouTube?" List of thrown errors: [AudienceInsightsError]() [AuthenticationError]() [AuthorizationError]() [FieldError]() [HeaderError]() [InternalError]() [QuotaError]() [RangeError]() [RequestError]() * * POST /v23/customers/{customersId}:generateTargetingSuggestionMetrics */ export const createApiV23CustomersCustomersIdGenerateTargetingSuggestionMetrics = async (args: CreateApiV23CustomersCustomersIdGenerateTargetingSuggestionMetricsArgs, options?: CreateApiV23CustomersCustomersIdGenerateTargetingSuggestionMetricsOptions) => { 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))}:generateTargetingSuggestionMetrics${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(googleAdsSearchads360V23ServicesGenerateTargetingSuggestionMetricsResponse, await res.json()) };