How do I get user activity data from the Google API

696 Views Asked by At

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?

  1. 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.

  2. 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

  1. Once the data has been retrieved from the GA API (which can sometimes take up to 15 minutes to populate in the GA databases), pass the full payload, including the lead details and the marketing characteristics through to the CRM.
0

There are 0 best solutions below