Skip to content

Latest commit

 

History

History
43 lines (36 loc) · 1.96 KB

File metadata and controls

43 lines (36 loc) · 1.96 KB

Google Analytics Data API examples

Open in Cloud Shell

These samples show how to use the Google Analytics Data API from Java.

Build and Run

  1. Enable APIs - Enable the Analytics Data 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
  3. Clone the repo and cd into this directory

    git clone https://github.com/googleanalytics/java-docs-samples
    cd java-docs-samples/google-analytics-data
  4. Confirm that Maven is installed

    mvn --version
  5. Review the comments starting with TODO(developer) and update the code to use correct values.

  6. Run with the command mvn compile exec:java -Dexec.mainClass=FULLY_QUALIFIED_SAMPLE_CLASS_NAME. For example:

    mvn -q compile exec:java -Dexec.mainClass='com.google.analytics.data.samples.QuickstartSample'

    Tip: You can see the complete list of available samples in the src/main/java/com/google/analytics/data/samples directory.