Skip to content

Commit

Permalink
Add separate README files for Admin and Data API samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jradcliff committed Nov 1, 2023
1 parent 6d9d357 commit 0abac6a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
37 changes: 37 additions & 0 deletions google-analytics-admin/README.md
Original file line number Diff line number Diff line change
@@ -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'
```

41 changes: 41 additions & 0 deletions google-analytics-data/README.md
Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 0abac6a

Please sign in to comment.