Google Analytics API v4

Using OAuth 2.0 for Server to Server Applications

The Google APIs Client Library for PHP supports using OAuth 2.0 for server-to-server interactions such as those between a web application and a Google service. For this scenario you need a service account, which is an account that belongs to your application instead of to an individual end user. Your application calls Google APIs on behalf of the service account, so users aren’t directly involved. Typically, an application uses a service account when the application uses Google APIs to work with its own data rather than a user’s data. Note: You need to add the service account email address as an authorized user of the view (profile) you want to access. Use this email address to add a user to the Google analytics view you want to access via the API.

Google API Client Library for PHP

The Google API Client Library for PHP is designed for PHP client-application developers. Read the PHP quickstart for service accounts how to access Google Analytics data.