These samples show how to use the Google Analytics Admin API from PHP.
- Enable APIs - Enable the Analytics Admin API and create a new project or select an existing project.
- Download The Credentials - Configure your project using Application Default Credentials.
Click "Go to credentials" after enabling the APIs. Click "Create Credentials"
and select "Service Account Credentials" and download the credentials file. Then set the path to
this file to the environment variable
GOOGLE_APPLICATION_CREDENTIALS
:
$ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
- Clone the repo and cd into this directory
$ git clone https://github.com/googleanalytics/php-docs-samples
$ cd php-docs-samples/google-analytics-admin
- Install dependencies via Composer.
Run
php composer.phar install
(if composer is installed locally) orcomposer install
(if composer is installed globally). - Replace
$property_id
variable if present in the snippet with the value of the Google Analytics 4 property id you want to access. - Run with the command
php SNIPPET_NAME.php
. For example:
$ php quickstart.php
- See CONTRIBUTING.md
- See LICENSE