-
How can I effectively utilize the Google Analytics API – Version 4?
Hey folks, so here’s what I did.
1. I logged a user in using Google account and scored a token. The code looks like this:
`
^ LaravelSocialiteTwoUser {#1512 ▼
+token: “ya29 — 51 ◀”
+refreshToken: null
+expiresIn: 3599
}
`
Sweet, that part worked.2. I got stuck trying to pull the list of account summaries the user can access, to find the viewId. Not sure where to find the key for this line: ‘https://analytics.googleapis.com/analytics/v3/management/accountSummaries?key=**WHERE_GET_THIS_KEY?**’
The code here goes like this:
`
curl
‘https://analytics.googleapis.com/analytics/v3/management/accountSummaries?key=**WHERE_GET_THIS_KEY?**’
–header ‘Authorization: Bearer ya29 — 51’
–header ‘Accept: application/json’
–compressed
`
Can anyone help me figure out where to dig up this key?3. Now that I’ve hopefully accomplished those things, I want to query with:
`
curl -X POST -H “Content-Type: application/json” -H “Authorization: Bearer ya29 — 51” -d ‘{
“reportRequests”:
[
{
“viewId”: “**FROM_PREVIOUS_QUERY**”,
“dateRanges”: [{“startDate”: “2014-11-01”, “endDate”: “2014-11-30”}],
“metrics”: [{“expression”: “ga:users”}]
}
]
}’ https://analyticsreporting.googleapis.com/v4/reports:batchGet
`
Couple of questions here folks– Can anybody help me out with getting the key for the second query?
– Is the third query in the right ballpark?Thanks, guys.
By the way, I used these resources:
– [BatchGet Guide](https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet?authuser=1)
– [Google Analytics Basics](https://developers.google.com/analytics/devguides/reporting/core/v4/basics)
– [Account Summaries List](https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accountSummaries/list?hl=ru&apix=true#try-it)
Log in to reply.