Question

I apologize if this seems like a basic question, but I just can't get my head around this. The Google Analytics API documentation isn't very consistent. Their tutorial uses the following format for API requests:

APIrequest

...yet, their documentation posits the following format for API requests:

enter image description here

In their documentation, there are a lot more resources using the second format, but I don't know how to apply these HTTP requests. Can anyone explain to me the difference and when I should use which? And how do you use the second format (HTTP requests)?

Was it helpful?

Solution

By using Googles v3 client library for PHP you don't need to deal with sending any of the HTTP Requests they are all dealt with for you via the library.

$accounts = $analytics->management_accounts->listManagementAccounts();

If you check $accounts now you have a nice list of objects representing each of the accounts you have access to. In the background that call is sending a Get to /managment/accounts asking for a list of all of all the accounts the authenticated user has access to. The results are returned in Json format. but all of that is behind the seens all you see is a nice list.

$webproperties = $analytics->management_webproperties->listManagementWebproperties($firstAccountId);

That call requests a list of all of the web properties under the Account from the first call above. Again you don't need to do the HTTP request to get the data all that is handled in the background.


Yes you could make all the calls yourself manually but its not easy. You have to build the request strings up correctly in order to do it. The results returned to you will be in Json format so you would have to deal with that as well. Its much easier to just use the API and get a list back of $accounts that you can use how ever you like.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top