Learn business growth with Google Analytics 4 Forums Google Analytics 4 Problems with provisioning Google Analytics 4 account token in PHP

  • Problems with provisioning Google Analytics 4 account token in PHP

    Posted by Raj on 8 November 2022 at 8:26 pm

    Hey all, I’m playing around with account provisioning functions in the Google Analytics 4 Admin API. All’s good until the point where I make the API call and get the provisioning ticket ID back. Here’s the script I whipped up to create the provisioning ticket:

        // more lines of code... 
        $tosBase = "https://analytics.google.com/analytics/web/?provisioningSignup=false#/termsofservice/";
        // oops, extra slash, but will that be a big deal?  
        $provisionURL = $tosBase . "/{$response->getAccountTicketId()}";

    I snuck that ticket right into the ToS URL like this:


    Showed that URL to my browser (incognito mode) and it threw a tantrum; came back with:

    Error: Account token is missing.

    So I thought “Alright, maybe the extra slash does matter!” Tried this:


    And boom, another error:

    Error: Access denied.

    Clearly, neither of these are the result I’m after. Any of you have an idea where I might be tripping up? Just as a heads-up, I’m using the alpha code for the AnalyticsAdminService client. Thanks in advance!

    Joseph replied 11 months, 2 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Harper

    27 May 2023 at 12:47 pm

    It seems like you’re having issues with the URL you’re generating for provisioning in Google Analytics 4 Admin API. The issue could be that the account token is either not being properly added to the URL, or it’s not being recognized. I suggest ensuring that your account token (TICKET_ID) is valid, and also double-checking the permission settings for your API. Finally, ensure that your URL formation is exactly as specified in the API documentation.

  • Joseph

    16 June 2023 at 10:02 pm

    Your issue might be related to the permissions of the user that is attempting to approve the account ticket. In order to approve an account ticket, the user must be logged in to a Google account and that account must have the ‘Provisioning’ permission. If the user does not have this permission, an ‘access denied’ error will appear. Check to ensure that the Google account has the needed permissions. Additionally, it’s advisable to ensure that the ticket ID is being correctly appended to the URL. Ensure there are no extra slashes or characters. This might be a reason for the ‘account token is missing’ error. If none of the above assists in solving the problem, it could be due to issues with the alpha version of the AnalyticsAdminService client. Remember that alpha versions are early releases that might not be fully tested or contain all final features.

Log in to reply.