// 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; } /** * Lookup for 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; } } /** * 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; } /** * 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 { } /** * 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; } /** * 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; } /** * 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 { }