Reputation: 21
I want to retrieve user activity data using the Google Analytics Reporting API. I code in PHP (not that it's relevant to this question)
I am following instructions from here: https://developers.google.com/analytics/devguides/reporting/core/v4/user-reporting
I am using the _ga client ID cookie stored in browser for the "userId", but I get the following response:
{ "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED", "details": [ { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "CREDENTIALS_MISSING", "domain": "googleapis.com", "metadata": { "service": "analyticsreporting.googleapis.com", "method": "google.analytics.reporting.v4.Reporting.SearchUserActivity" } } ] } }
This seems like I have to let the user sign into Google before I can get the desired data.
Is it possible to get this data from just the _ga cookie ID, without the user signing in?
Below is the request from the client. They say I need to use the Google Reporting API. This also seems like it can only work once signed in?
When a lead is submitted using the contact form, capture the Google Analytics ClientID (stored in the _ga cookie in the browser) as part of the submission.
Using the ClientID, interrogate the Google Analytics Reporting API for the "first interaction" (first session) user activity linked to this lead, fetching the data linked to the following variables:
Source
Medium
Campaign Name
Campaign Content
Campaign Term
Search Query
Upvotes: 0
Views: 925
Reputation: 1
This API is gone.
Basically you can get a client-credentials.json from the API console. Allow any mail IDs you want to allow.
Use this code for logging in and getting a user access token.
If you search you will be able get REST methods to do this as well.
Code: https://github.com/Underemployed/Google-Photos-Downloader/blob/main/Google.py
Upvotes: 0