So my task is to create a web app in PHP which will do this:
- output total number of visitors on the site
- output the name of the country from where the most visitors came from
So far I have done this:
- Created a project in API console
- Enabled API
- Created credentials
- Successfully setup sample
When I run the sample, it outputs the name of the authorized user's first Google Analytics view and the number of sessions for the last seven days. I followed these instructions: https://developers.google.com/analytics/devguides/config/mgmt/v3/quickstart/web-php
I analyzed the code and figured out that in order to call Core Reporting API, it's required to get Profile ID of the user.
function getResults($analytics, $profileId) {
return $analytics->data_ga->get(
'ga:' . $profileId,
'7daysAgo',
'today',
'ga:sessions');
}
To get the Profile ID, the function getFirstProfileId is used (you can see it on the link I provided).
So my question is - how do I make it work so it outputs total number of visitors on my page. Do I have to skip part where I get profileID, and if that's true, how do I call Core Reporting API?