import {z} from 'zod' export type GoogleAdsSearchads360V23ServicesAudienceInsightsDimensions = {dimensions?: (Array<'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'>) | undefined}; export type GoogleAdsSearchads360V23CommonLocationInfo = {geoTargetConstant?: string | undefined}; export type GoogleAdsSearchads360V23ServicesInsightsAudienceDescription = {audienceDescription?: string | undefined, audienceDimensions?: GoogleAdsSearchads360V23ServicesAudienceInsightsDimensions | undefined, countryLocations?: Array | undefined, marketingObjective?: ('UNSPECIFIED' | 'UNKNOWN' | 'AWARENESS' | 'CONSIDERATION' | 'RESEARCH') | undefined}; export type GoogleAdsSearchads360V23CommonAdditionalApplicationInfo = {applicationId?: string | undefined, applicationInstance?: ('UNSPECIFIED' | 'UNKNOWN' | 'DEVELOPMENT_AND_TESTING' | 'PRODUCTION') | undefined}; export type GoogleAdsSearchads360V23ServicesGenerateAudienceDefinitionRequest = {audienceDescription?: GoogleAdsSearchads360V23ServicesInsightsAudienceDescription | undefined, customerInsightsGroup?: string | undefined, insightsApplicationInfo?: GoogleAdsSearchads360V23CommonAdditionalApplicationInfo | undefined}; export type CreateApiV23CustomersCustomersIdGenerateAudienceDefinitionArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesGenerateAudienceDefinitionRequest}; export type CreateApiV23CustomersCustomersIdGenerateAudienceDefinitionOptions = {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 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 googleAdsSearchads360V23CommonGenderInfo = z.object({type: z.enum(["UNSPECIFIED", "UNKNOWN", "MALE", "FEMALE", "UNDETERMINED"]).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 googleAdsSearchads360V23ServicesGenerateAudienceDefinitionResponse = z.object({highRelevanceAttributes: z.array(googleAdsSearchads360V23CommonAudienceInsightsAttributeMetadata).optional(), mediumRelevanceAttributes: z.array(googleAdsSearchads360V23CommonAudienceInsightsAttributeMetadata).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 a collection of audience attributes using generative AI based on the provided audience description. List of thrown errors: [AudienceInsightsError]() [AuthenticationError]() [AuthorizationError]() [FieldError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]() * * POST /v23/customers/{customersId}:generateAudienceDefinition */ export const createApiV23CustomersCustomersIdGenerateAudienceDefinition = async (args: CreateApiV23CustomersCustomersIdGenerateAudienceDefinitionArgs, options?: CreateApiV23CustomersCustomersIdGenerateAudienceDefinitionOptions) => { 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))}:generateAudienceDefinition${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(googleAdsSearchads360V23ServicesGenerateAudienceDefinitionResponse, await res.json()) };