Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 1.91 KB

File metadata and controls

48 lines (37 loc) · 1.91 KB

Google Analytics Admin API Samples

Open in Cloud Shell

Description

These samples show how to use the Google Analytics Admin API from PHP.

Build and Run

  1. Enable APIs - Enable the Analytics Admin API and create a new project or select an existing project.
  2. 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
  1. Clone the repo and cd into this directory
    $ git clone https://github.com/googleanalytics/php-docs-samples
    $ cd php-docs-samples/google-analytics-admin
  1. Install dependencies via Composer. Run php composer.phar install (if composer is installed locally) or composer install (if composer is installed globally).
  2. Replace $property_id variable if present in the snippet with the value of the Google Analytics 4 property id you want to access.
  3. Run with the command php SNIPPET_NAME.php. For example:
    $ php quickstart.php

Contributing changes

Licensing