From 0abac6afc7b5bd6ae98297752e0a1c78980c0868 Mon Sep 17 00:00:00 2001 From: Josh Radcliff Date: Wed, 1 Nov 2023 16:50:20 -0400 Subject: [PATCH] Add separate README files for Admin and Data API samples --- google-analytics-admin/README.md | 37 +++++++++++++++++ .../QuickstartSample.java | 0 google-analytics-data/README.md | 41 +++++++++++++++++++ .../example/analytics/QuickstartSample.java | 2 +- 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 google-analytics-admin/README.md rename google-analytics-admin/src/main/java/com/example/{analyticsadmin => analytics}/QuickstartSample.java (100%) create mode 100644 google-analytics-data/README.md diff --git a/google-analytics-admin/README.md b/google-analytics-admin/README.md new file mode 100644 index 00000000..bbe90b60 --- /dev/null +++ b/google-analytics-admin/README.md @@ -0,0 +1,37 @@ +# Google Analytics Admin API examples + +[![Open in Cloud Shell][shell_img]][shell_link] + +[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png +[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleanalytics/java-docs-samples&page=editor&open_in_editor=/google-analytics-admin/README.md + +These samples show how to use the +[Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1) from Python. + +## Build and Run +1. **Enable APIs** - [Enable the Analytics Data API](https://console.cloud.google.com/flows/enableapi?apiid=analyticsdata.googleapis.com) + and create a new project or select an existing project. +2. **Download The Credentials** - Configure your project using [Application Default Credentials][adc]. + 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`: + ```sh + export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json + ``` +3. **Clone the repo** and cd into this directory + ```sh + git clone https://github.com/googleanalytics/java-docs-samples + cd java-docs-samples/google-analytics-admin + ``` +4. Confirm that [Maven](https://maven.apache.org) is installed + ```sh + 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: + ```sh + mvn -q compile exec:java -Dexec.mainClass='com.example.analytics.QuickstartSample' + ``` + diff --git a/google-analytics-admin/src/main/java/com/example/analyticsadmin/QuickstartSample.java b/google-analytics-admin/src/main/java/com/example/analytics/QuickstartSample.java similarity index 100% rename from google-analytics-admin/src/main/java/com/example/analyticsadmin/QuickstartSample.java rename to google-analytics-admin/src/main/java/com/example/analytics/QuickstartSample.java diff --git a/google-analytics-data/README.md b/google-analytics-data/README.md new file mode 100644 index 00000000..ba61199a --- /dev/null +++ b/google-analytics-data/README.md @@ -0,0 +1,41 @@ +# Google Analytics Data API examples + +[![Open in Cloud Shell][shell_img]][shell_link] + +[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png +[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleanalytics/java-docs-samples&page=editor&open_in_editor=/google-analytics-data/README.md + +These samples show how to use the +[Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1) from Python. + +## Build and Run +1. **Enable APIs** - [Enable the Analytics Data API](https://console.cloud.google.com/flows/enableapi?apiid=analyticsdata.googleapis.com) + and create a new project or select an existing project. +2. **Download The Credentials** - Configure your project using [Application Default Credentials][adc]. + 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`: + + ```sh + export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json + ``` +3. **Clone the repo** and cd into this directory + ```sh + git clone https://github.com/googleanalytics/java-docs-samples + cd java-docs-samples/google-analytics-admin + ``` +4. Confirm that [Maven](https://maven.apache.org) is installed + ```sh + 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: + ```sh + mvn -q compile exec:java -Dexec.mainClass='com.example.analytics.QuickstartSample' + ``` + **Tip:** You can see the complete list of available samples in the + [`src/main/java/com/example/analytics`][src/main/java/com/example/analytics] + directory. + diff --git a/google-analytics-data/src/main/java/com/example/analytics/QuickstartSample.java b/google-analytics-data/src/main/java/com/example/analytics/QuickstartSample.java index 7186562a..55434315 100644 --- a/google-analytics-data/src/main/java/com/example/analytics/QuickstartSample.java +++ b/google-analytics-data/src/main/java/com/example/analytics/QuickstartSample.java @@ -45,7 +45,7 @@ public static void main(String... args) throws Exception { * TODO(developer): Replace this variable with your Google Analytics 4 property ID before * running the sample. */ - String propertyId = "YOUR-GA4-PROPERTY-ID"; + String propertyId = "355158046"; sampleRunReport(propertyId); }