goldylucks
goldylucks

Reputation: 6144

Create account through google analytics v4 admin API

I need to create g4 analytics accounts at scale.

I made a call to the API according to the docs:

apiClient.request({
      method: "POST",
      url: "https://analyticsadmin.googleapis.com/v1alpha/accounts:provisionAccountTicket",
      data: {
        account: {
          displayName: "Test Account",
          regionCode: "US",
        },
        redirectUri: "https://my-redirect-url",
      },
    }),

And I got this response:

{ accountTicketId: "4iR-Ogm8RDSMoV3lQpjZjQ" }

How do I proceed here? What's the next step?

Upvotes: 2

Views: 751

Answers (3)

evro
evro

Reputation: 1

Ideally there would be a way to do this with a service account but that's not possible do to security I think. You would need to have the user creating the request to accept TOS by going to 'https://analytics.google.com/analytics/web/?provisioningSignup=false#/termsofservice/TICKETNUMBER'. I'm actually working on something similar at scale for GTM and GA4 so this is one of the many problems I'm facing.

Also see ref code from git: https://github.com/googleapis/python-analytics-admin/blob/main/samples/accounts_provision_account_ticket.py

Upvotes: 0

Gampesh
Gampesh

Reputation: 4374

As per previous comment and as it is mentioned in the Google's api documentation

request = {
          account,
          redirectUri
          };
          const newAc = await analyticsAdminClient.provisionAccountTicket(request);
          console.log(`https://analytics.google.com/analytics/web/?provisioningSignup=false#/termsofservice/${newAc[0].accountTicketId}`);

Console statement from above url will take you to Google's TOC page, just accept the T&C and you are done. Account will be created.

Upvotes: 0

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116918

As per account provsioning.

This method returns the accountTicketId field that should be included in the Terms of Service (TOS) URL: https://analytics.google.com/analytics/web/?provisioningSignup=false#/termsofservice/ACCOUNT_TICKET_ID. Once a user visits the TOS URL and accepts the Terms of Service, creation of a Google Analytics account will be complete (Account provisioning sample).

So the next step would be to have the user visit the page listed and approve the TOS.

Upvotes: 2

Related Questions