// Copyright 2022 Luca Casonato. All rights reserved. MIT license. /** * Google Marketing Platform Admin API Client for Deno * =================================================== * * The Google Marketing Platform Admin API allows for programmatic access to the Google Marketing Platform configuration data. You can use the Google Marketing Platform Admin API to manage links between your Google Marketing Platform organization and Google Analytics accounts, and to set the service level of your GA4 properties. * * Docs: https://developers.google.com/analytics/devguides/config/gmp/v1 * Source: https://googleapis.deno.dev/v1/marketingplatformadmin:v1alpha.ts */ import { auth, CredentialsClient, GoogleAuth, request } from "/_/base@v1/mod.ts"; export { auth, GoogleAuth }; export type { CredentialsClient }; /** * The Google Marketing Platform Admin API allows for programmatic access to * the Google Marketing Platform configuration data. You can use the Google * Marketing Platform Admin API to manage links between your Google Marketing * Platform organization and Google Analytics accounts, and to set the service * level of your GA4 properties. */ export class MarketingPlatformAdmin { #client: CredentialsClient | undefined; #baseUrl: string; constructor(client?: CredentialsClient, baseUrl: string = "https://marketingplatformadmin.googleapis.com/") { this.#client = client; this.#baseUrl = baseUrl; } /** * Creates the link between the Analytics account and the Google Marketing * Platform organization. User needs to be an org user, and admin on the * Analytics account to create the link. If the account is already linked to * an organization, user needs to unlink the account from the current * organization, then try link again. * * @param parent Required. The parent resource where this Analytics account link will be created. Format: organizations/{org_id} */ async organizationsAnalyticsAccountLinksCreate(parent: string, req: AnalyticsAccountLink): Promise { const url = new URL(`${this.#baseUrl}v1alpha/${ parent }/analyticsAccountLinks`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as AnalyticsAccountLink; } /** * Deletes the AnalyticsAccountLink, which detaches the Analytics account * from the Google Marketing Platform organization. User needs to be an org * user, and admin on the Analytics account in order to delete the link. * * @param name Required. The name of the Analytics account link to delete. Format: organizations/{org_id}/analyticsAccountLinks/{analytics_account_link_id} */ async organizationsAnalyticsAccountLinksDelete(name: string): Promise { const url = new URL(`${this.#baseUrl}v1alpha/${ name }`); const data = await request(url.href, { client: this.#client, method: "DELETE", }); return data as Empty; } /** * Lists the Google Analytics accounts link to the specified Google Marketing * Platform organization. * * @param parent Required. The parent organization, which owns this collection of Analytics account links. Format: organizations/{org_id} */ async organizationsAnalyticsAccountLinksList(parent: string, opts: OrganizationsAnalyticsAccountLinksListOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1alpha/${ parent }/analyticsAccountLinks`); if (opts.pageSize !== undefined) { url.searchParams.append("pageSize", String(opts.pageSize)); } if (opts.pageToken !== undefined) { url.searchParams.append("pageToken", String(opts.pageToken)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return data as ListAnalyticsAccountLinksResponse; } /** * Updates the service level for an Analytics property. * * @param analyticsAccountLink Required. The parent AnalyticsAccountLink scope where this property is in. Format: organizations/{org_id}/analyticsAccountLinks/{analytics_account_link_id} */ async organizationsAnalyticsAccountLinksSetPropertyServiceLevel(analyticsAccountLink: string, req: SetPropertyServiceLevelRequest): Promise { const url = new URL(`${this.#baseUrl}v1alpha/${ analyticsAccountLink }:setPropertyServiceLevel`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as SetPropertyServiceLevelResponse; } /** * Returns a list of clients managed by the sales partner organization. User * needs to be an OrgAdmin/BillingAdmin on the sales partner organization in * order to view the end clients. * * @param organization Required. The name of the sales partner organization. Format: organizations/{org_id} */ async organizationsFindSalesPartnerManagedClients(organization: string, req: FindSalesPartnerManagedClientsRequest): Promise { const url = new URL(`${this.#baseUrl}v1alpha/${ organization }:findSalesPartnerManagedClients`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as FindSalesPartnerManagedClientsResponse; } /** * Looks up a single organization. * * @param name Required. The name of the Organization to retrieve. Format: organizations/{org_id} */ async organizationsGet(name: string): Promise { const url = new URL(`${this.#baseUrl}v1alpha/${ name }`); const data = await request(url.href, { client: this.#client, method: "GET", }); return data as Organization; } /** * Returns a list of organizations that the user has access to. * */ async organizationsList(opts: OrganizationsListOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1alpha/organizations`); if (opts.pageSize !== undefined) { url.searchParams.append("pageSize", String(opts.pageSize)); } if (opts.pageToken !== undefined) { url.searchParams.append("pageToken", String(opts.pageToken)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return data as ListOrganizationsResponse; } /** * Gets the usage and billing data for properties within the organization for * the specified month. Per direct client org, user needs to be * OrgAdmin/BillingAdmin on the organization in order to view the billing and * usage data. Per sales partner client org, user needs to be * OrgAdmin/BillingAdmin on the sales partner org in order to view the billing * and usage data, or OrgAdmin/BillingAdmin on the sales partner client org in * order to view the usage data only. * * @param organization Required. Specifies the organization whose property usage will be listed. Format: organizations/{org_id} */ async organizationsReportPropertyUsage(organization: string, req: ReportPropertyUsageRequest): Promise { const url = new URL(`${this.#baseUrl}v1alpha/${ organization }:reportPropertyUsage`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return deserializeReportPropertyUsageResponse(data); } } /** * A resource message representing the link between a Google Analytics account * and a Google Marketing Platform organization. */ export interface AnalyticsAccountLink { /** * Required. Immutable. The resource name of the AnalyticsAdmin API account. * The account ID will be used as the ID of this AnalyticsAccountLink * resource, which will become the final component of the resource name. * Format: analyticsadmin.googleapis.com/accounts/{account_id} */ analyticsAccount?: string; /** * Output only. The human-readable name for the Analytics account. */ readonly displayName?: string; /** * Output only. The verification state of the link between the Analytics * account and the parent organization. */ readonly linkVerificationState?: | "LINK_VERIFICATION_STATE_UNSPECIFIED" | "LINK_VERIFICATION_STATE_VERIFIED" | "LINK_VERIFICATION_STATE_NOT_VERIFIED"; /** * Identifier. Resource name of this AnalyticsAccountLink. Note the resource * ID is the same as the ID of the Analtyics account. Format: * organizations/{org_id}/analyticsAccountLinks/{analytics_account_link_id} * Example: "organizations/xyz/analyticsAccountLinks/1234" */ name?: string; } /** * Contains the bill amount. */ export interface BillInfo { /** * The amount of the monthly base fee. */ baseFee?: Money; /** * The amount of the event fee. */ eventFee?: Money; /** * The amount of the price protection credit, this is only available for * eligible customers. */ priceProtectionCredit?: Money; /** * The total amount of the bill. */ total?: Money; } function serializeBillInfo(data: any): BillInfo { return { ...data, baseFee: data["baseFee"] !== undefined ? serializeMoney(data["baseFee"]) : undefined, eventFee: data["eventFee"] !== undefined ? serializeMoney(data["eventFee"]) : undefined, priceProtectionCredit: data["priceProtectionCredit"] !== undefined ? serializeMoney(data["priceProtectionCredit"]) : undefined, total: data["total"] !== undefined ? serializeMoney(data["total"]) : undefined, }; } function deserializeBillInfo(data: any): BillInfo { return { ...data, baseFee: data["baseFee"] !== undefined ? deserializeMoney(data["baseFee"]) : undefined, eventFee: data["eventFee"] !== undefined ? deserializeMoney(data["eventFee"]) : undefined, priceProtectionCredit: data["priceProtectionCredit"] !== undefined ? deserializeMoney(data["priceProtectionCredit"]) : undefined, total: data["total"] !== undefined ? deserializeMoney(data["total"]) : undefined, }; } /** * Contains the client data. */ export interface ClientData { /** * The end date of the contract between the sales org and the end client. */ endDate?: Date; /** * The end client that has/had contract with the requested sales org. */ organization?: Organization; /** * The start date of the contract between the sales org and the end client. */ startDate?: Date; } /** * Represents a whole or partial calendar date, such as a birthday. The time of * day and time zone are either specified elsewhere or are insignificant. The * date is relative to the Gregorian Calendar. This can represent one of the * following: * A full date, with non-zero year, month, and day values. * A * month and day, with a zero year (for example, an anniversary). * A year on * its own, with a zero month and a zero day. * A year and month, with a zero * day (for example, a credit card expiration date). Related types: * * google.type.TimeOfDay * google.type.DateTime * google.protobuf.Timestamp */ export interface Date { /** * Day of a month. Must be from 1 to 31 and valid for the year and month, or * 0 to specify a year by itself or a year and month where the day isn't * significant. */ day?: number; /** * Month of a year. Must be from 1 to 12, or 0 to specify a year without a * month and day. */ month?: number; /** * Year of the date. Must be from 1 to 9999, or 0 to specify a date without a * year. */ year?: number; } /** * A generic empty message that you can re-use to avoid defining duplicated * empty messages in your APIs. A typical example is to use it as the request or * the response type of an API method. For instance: service Foo { rpc * Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } */ export interface Empty { } /** * Request message for FindSalesPartnerManagedClients RPC. */ export interface FindSalesPartnerManagedClientsRequest { /** * Optional. If set, only active and just ended clients will be returned. */ isActive?: boolean; } /** * Response message for FindSalesPartnerManagedClients RPC. */ export interface FindSalesPartnerManagedClientsResponse { /** * The clients managed by the sales org. */ clientData?: ClientData[]; } /** * Response message for ListAnalyticsAccountLinks RPC. */ export interface ListAnalyticsAccountLinksResponse { /** * Analytics account links in this organization. */ analyticsAccountLinks?: AnalyticsAccountLink[]; /** * A token, which can be sent as `page_token` to retrieve the next page. If * this field is omitted, there are no subsequent pages. */ nextPageToken?: string; } /** * Response message for ListOrganizations RPC. */ export interface ListOrganizationsResponse { /** * A token, which can be sent as `page_token` to retrieve the next page. If * this field is omitted, there are no subsequent pages. */ nextPageToken?: string; /** * The Organization resource that the user has access to, which includes the * org id and display name. */ organizations?: Organization[]; } /** * Represents an amount of money with its currency type. */ export interface Money { /** * The three-letter currency code defined in ISO 4217. */ currencyCode?: string; /** * Number of nano (10^-9) units of the amount. The value must be between * -999,999,999 and +999,999,999 inclusive. If `units` is positive, `nanos` * must be positive or zero. If `units` is zero, `nanos` can be positive, * zero, or negative. If `units` is negative, `nanos` must be negative or * zero. For example $-1.75 is represented as `units`=-1 and * `nanos`=-750,000,000. */ nanos?: number; /** * The whole units of the amount. For example if `currencyCode` is `"USD"`, * then 1 unit is one US dollar. */ units?: bigint; } function serializeMoney(data: any): Money { return { ...data, units: data["units"] !== undefined ? String(data["units"]) : undefined, }; } function deserializeMoney(data: any): Money { return { ...data, units: data["units"] !== undefined ? BigInt(data["units"]) : undefined, }; } /** * A resource message representing a Google Marketing Platform organization. */ export interface Organization { /** * The human-readable name for the organization. */ displayName?: string; /** * Identifier. The resource name of the GMP organization. Format: * organizations/{org_id} */ name?: string; } /** * Additional options for * MarketingPlatformAdmin#organizationsAnalyticsAccountLinksList. */ export interface OrganizationsAnalyticsAccountLinksListOptions { /** * Optional. The maximum number of Analytics account links to return in one * call. The service may return fewer than this value. If unspecified, at most * 50 Analytics account links will be returned. The maximum value is 1000; * values above 1000 will be coerced to 1000. */ pageSize?: number; /** * Optional. A page token, received from a previous ListAnalyticsAccountLinks * call. Provide this to retrieve the subsequent page. When paginating, all * other parameters provided to `ListAnalyticsAccountLinks` must match the * call that provided the page token. */ pageToken?: string; } /** * Additional options for MarketingPlatformAdmin#organizationsList. */ export interface OrganizationsListOptions { /** * Optional. The maximum number of organizations to return in one call. The * service may return fewer than this value. If unspecified, at most 50 * organizations will be returned. The maximum value is 1000; values above * 1000 will be coerced to 1000. */ pageSize?: number; /** * Optional. A page token, received from a previous ListOrganizations call. * Provide this to retrieve the subsequent page. When paginating, all other * parameters provided to `ListOrganizations` must match the call that * provided the page token. */ pageToken?: string; } /** * Contains the count of events received by the property, along with metadata * that influences the volume of `billable` events. */ export interface PropertyUsage { /** * The ID of the property's parent account. */ accountId?: bigint; /** * The number of events for which the property is billed in the requested * month. */ billableEventCount?: bigint; /** * The display name of the property. */ displayName?: string; /** * The name of the Google Analytics Admin API property resource. Format: * analyticsadmin.googleapis.com/properties/{property_id} */ property?: string; /** * The subtype of the analytics property. This affects the billable event * count. */ propertyType?: | "ANALYTICS_PROPERTY_TYPE_UNSPECIFIED" | "ANALYTICS_PROPERTY_TYPE_ORDINARY" | "ANALYTICS_PROPERTY_TYPE_SUBPROPERTY" | "ANALYTICS_PROPERTY_TYPE_ROLLUP"; /** * The service level of the property. */ serviceLevel?: | "ANALYTICS_SERVICE_LEVEL_UNSPECIFIED" | "ANALYTICS_SERVICE_LEVEL_STANDARD" | "ANALYTICS_SERVICE_LEVEL_360"; /** * Total event count that the property received during the requested month. */ totalEventCount?: bigint; } function serializePropertyUsage(data: any): PropertyUsage { return { ...data, accountId: data["accountId"] !== undefined ? String(data["accountId"]) : undefined, billableEventCount: data["billableEventCount"] !== undefined ? String(data["billableEventCount"]) : undefined, totalEventCount: data["totalEventCount"] !== undefined ? String(data["totalEventCount"]) : undefined, }; } function deserializePropertyUsage(data: any): PropertyUsage { return { ...data, accountId: data["accountId"] !== undefined ? BigInt(data["accountId"]) : undefined, billableEventCount: data["billableEventCount"] !== undefined ? BigInt(data["billableEventCount"]) : undefined, totalEventCount: data["totalEventCount"] !== undefined ? BigInt(data["totalEventCount"]) : undefined, }; } /** * Request message for ReportPropertyUsage RPC. */ export interface ReportPropertyUsageRequest { /** * Required. The target month to list property usages. Format: YYYY-MM. For * example, "2025-05" */ month?: string; } /** * Response message for ReportPropertyUsage RPC. */ export interface ReportPropertyUsageResponse { /** * Bill amount in the specified organization and month. Will be empty if user * only has access to usage data. */ billInfo?: BillInfo; /** * Usage data for all properties in the specified organization and month. */ propertyUsages?: PropertyUsage[]; } function serializeReportPropertyUsageResponse(data: any): ReportPropertyUsageResponse { return { ...data, billInfo: data["billInfo"] !== undefined ? serializeBillInfo(data["billInfo"]) : undefined, propertyUsages: data["propertyUsages"] !== undefined ? data["propertyUsages"].map((item: any) => (serializePropertyUsage(item))) : undefined, }; } function deserializeReportPropertyUsageResponse(data: any): ReportPropertyUsageResponse { return { ...data, billInfo: data["billInfo"] !== undefined ? deserializeBillInfo(data["billInfo"]) : undefined, propertyUsages: data["propertyUsages"] !== undefined ? data["propertyUsages"].map((item: any) => (deserializePropertyUsage(item))) : undefined, }; } /** * Request message for SetPropertyServiceLevel RPC. */ export interface SetPropertyServiceLevelRequest { /** * Required. The Analytics property to change the ServiceLevel setting. This * field is the name of the Google Analytics Admin API property resource. * Format: analyticsadmin.googleapis.com/properties/{property_id} */ analyticsProperty?: string; /** * Required. The service level to set for this property. */ serviceLevel?: | "ANALYTICS_SERVICE_LEVEL_UNSPECIFIED" | "ANALYTICS_SERVICE_LEVEL_STANDARD" | "ANALYTICS_SERVICE_LEVEL_360"; } /** * Response message for SetPropertyServiceLevel RPC. */ export interface SetPropertyServiceLevelResponse { }