diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 426cf83e..f60d7749 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,4 +13,5 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest - digest: sha256:b0b1c1c89570e229b1026372a2b8989ba31495007055b8d30178b7648503eefa + digest: sha256:fc52b202aa298a50a12c64efd04fea3884d867947effe2fa85382a246c09e813 +# created: 2022-04-06T16:30:03.627422514Z diff --git a/.github/auto-label.yaml b/.github/auto-label.yaml new file mode 100644 index 00000000..4caef688 --- /dev/null +++ b/.github/auto-label.yaml @@ -0,0 +1,15 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +requestsize: + enabled: true diff --git a/CHANGELOG.md b/CHANGELOG.md index a677be26..6d15450b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [0.11.10](https://github.com/googleapis/java-analytics-data/compare/v0.11.9...v0.11.10) (2022-04-15) + + +### Dependencies + +* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.10.0 ([#478](https://github.com/googleapis/java-analytics-data/issues/478)) ([0346b09](https://github.com/googleapis/java-analytics-data/commit/0346b09955c53309cc4d34497f5f075f73c78a8e)) + ### [0.11.9](https://github.com/googleapis/java-analytics-data/compare/v0.11.8...v0.11.9) (2022-03-29) diff --git a/README.md b/README.md index c3444c1a..12bfdbe7 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,20 @@ If you are using Maven, add this to your pom.xml file: com.google.analytics google-analytics-data - 0.11.8 + 0.11.9 ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.analytics:google-analytics-data:0.11.8' +implementation 'com.google.analytics:google-analytics-data:0.11.9' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.analytics" % "google-analytics-data" % "0.11.8" +libraryDependencies += "com.google.analytics" % "google-analytics-data" % "0.11.9" ``` ## Authentication @@ -82,6 +82,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-analytics-dat | Quickstart Json Credentials Sample | [source code](https://github.com/googleapis/java-analytics-data/blob/main/samples/snippets/src/main/java/com/example/analytics/QuickstartJsonCredentialsSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-analytics-data&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/analytics/QuickstartJsonCredentialsSample.java) | | Quickstart Sample | [source code](https://github.com/googleapis/java-analytics-data/blob/main/samples/snippets/src/main/java/com/example/analytics/QuickstartSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-analytics-data&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/analytics/QuickstartSample.java) | | Run Report Sample | [source code](https://github.com/googleapis/java-analytics-data/blob/main/samples/snippets/src/main/java/com/example/analytics/RunReportSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-analytics-data&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/analytics/RunReportSample.java) | +| Run Report With Aggregations Sample | [source code](https://github.com/googleapis/java-analytics-data/blob/main/samples/snippets/src/main/java/com/example/analytics/RunReportWithAggregationsSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-analytics-data&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/analytics/RunReportWithAggregationsSample.java) | +| Run Report With Cohorts Sample | [source code](https://github.com/googleapis/java-analytics-data/blob/main/samples/snippets/src/main/java/com/example/analytics/RunReportWithCohortsSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-analytics-data&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/analytics/RunReportWithCohortsSample.java) | diff --git a/google-analytics-data-bom/pom.xml b/google-analytics-data-bom/pom.xml index 2a2e988d..2910c849 100644 --- a/google-analytics-data-bom/pom.xml +++ b/google-analytics-data-bom/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.analytics google-analytics-data-bom - 0.11.9 + 0.11.10 pom com.google.cloud @@ -56,17 +56,17 @@ com.google.analytics google-analytics-data - 0.11.9 + 0.11.10 com.google.api.grpc grpc-google-analytics-data-v1beta - 0.11.9 + 0.11.10 com.google.api.grpc proto-google-analytics-data-v1beta - 0.11.9 + 0.11.10 diff --git a/google-analytics-data/pom.xml b/google-analytics-data/pom.xml index 653edb6a..2462e75d 100644 --- a/google-analytics-data/pom.xml +++ b/google-analytics-data/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.analytics google-analytics-data - 0.11.9 + 0.11.10 jar Google Analytics Data https://github.com/googleapis/java-analytics-data @@ -11,7 +11,7 @@ com.google.analytics google-analytics-data-parent - 0.11.9 + 0.11.10 google-analytics-data diff --git a/grpc-google-analytics-data-v1beta/pom.xml b/grpc-google-analytics-data-v1beta/pom.xml index 0cd9ee37..42ef8430 100644 --- a/grpc-google-analytics-data-v1beta/pom.xml +++ b/grpc-google-analytics-data-v1beta/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-analytics-data-v1beta - 0.11.9 + 0.11.10 grpc-google-analytics-data-v1beta GRPC library for grpc-google-analytics-data-v1beta com.google.analytics google-analytics-data-parent - 0.11.9 + 0.11.10 diff --git a/pom.xml b/pom.xml index d17427b4..f2a5bf21 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.analytics google-analytics-data-parent pom - 0.11.9 + 0.11.10 Google Analytics Data Parent https://github.com/googleapis/java-analytics-data @@ -61,23 +61,23 @@ com.google.analytics google-analytics-data - 0.11.9 + 0.11.10 com.google.api.grpc proto-google-analytics-data-v1beta - 0.11.9 + 0.11.10 com.google.api.grpc grpc-google-analytics-data-v1beta - 0.11.9 + 0.11.10 com.google.cloud google-cloud-shared-dependencies - 2.9.0 + 2.10.0 pom import diff --git a/proto-google-analytics-data-v1beta/pom.xml b/proto-google-analytics-data-v1beta/pom.xml index decf9262..f965f54e 100644 --- a/proto-google-analytics-data-v1beta/pom.xml +++ b/proto-google-analytics-data-v1beta/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-analytics-data-v1beta - 0.11.9 + 0.11.10 proto-google-analytics-data-v1beta PROTO library for proto-google-analytics-data-v1beta com.google.analytics google-analytics-data-parent - 0.11.9 + 0.11.10 diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index 84f0e13b..3ce6f136 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -29,7 +29,7 @@ com.google.analytics google-analytics-data - 0.11.6 + 0.11.9 diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 95feba66..a20a135e 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -28,7 +28,7 @@ com.google.cloud libraries-bom - 25.0.0 + 25.1.0 pom import @@ -40,7 +40,7 @@ com.google.analytics google-analytics-data - 0.11.9 + 0.11.10 diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index 45dc890f..0fc3f35f 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -28,7 +28,7 @@ com.google.cloud libraries-bom - 25.0.0 + 25.1.0 pom import @@ -40,7 +40,7 @@ com.google.analytics google-analytics-data - 0.11.6 + 0.11.9 com.google.auth diff --git a/samples/snippets/src/main/java/com/example/analytics/QuickstartSample.java b/samples/snippets/src/main/java/com/example/analytics/QuickstartSample.java index 32983df9..7186562a 100644 --- a/samples/snippets/src/main/java/com/example/analytics/QuickstartSample.java +++ b/samples/snippets/src/main/java/com/example/analytics/QuickstartSample.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Google LLC + * Copyright 2022 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,12 +52,6 @@ public static void main(String... args) throws Exception { // This is an example snippet that calls the Google Analytics Data API and runs a simple report // on the provided GA4 property id. static void sampleRunReport(String propertyId) throws Exception { - /** - * TODO(developer): Uncomment this variable and replace with your Google Analytics 4 property ID - * before running the sample. - */ - // propertyId = "YOUR-GA4-PROPERTY-ID"; - // [START analyticsdata_initialize] // Using a default constructor instructs the client to use the credentials // specified in GOOGLE_APPLICATION_CREDENTIALS environment variable. diff --git a/samples/snippets/src/main/java/com/example/analytics/RunReportSample.java b/samples/snippets/src/main/java/com/example/analytics/RunReportSample.java index 1db677f6..0dbb8c16 100644 --- a/samples/snippets/src/main/java/com/example/analytics/RunReportSample.java +++ b/samples/snippets/src/main/java/com/example/analytics/RunReportSample.java @@ -23,8 +23,6 @@ https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport for more information. -This application demonstrates the usage of the Analytics Data API using service account credentials. - Before you start the application, please review the comments starting with "TODO(developer)" and update the code to use correct values. @@ -58,11 +56,6 @@ public static void main(String... args) throws Exception { // Runs a report of active users grouped by country. static void sampleRunReport(String propertyId) throws Exception { - /** - * TODO(developer): Uncomment this variable and replace with your Google Analytics 4 property ID - * before running the sample. - */ - // propertyId = "YOUR-GA4-PROPERTY-ID"; // Using a default constructor instructs the client to use the credentials // specified in GOOGLE_APPLICATION_CREDENTIALS environment variable. @@ -92,7 +85,7 @@ static void printRunResponseResponse(RunReportResponse response) { } for (MetricHeader header : response.getMetricHeadersList()) { - System.out.printf("Metric header name: %s%n", header.getName()); + System.out.printf("Metric header name: %s (%s)%n", header.getName(), header.getType()); } // [END analyticsdata_print_run_report_response_header] diff --git a/samples/snippets/src/main/java/com/example/analytics/RunReportWithAggregationsSample.java b/samples/snippets/src/main/java/com/example/analytics/RunReportWithAggregationsSample.java new file mode 100644 index 00000000..55d6a88d --- /dev/null +++ b/samples/snippets/src/main/java/com/example/analytics/RunReportWithAggregationsSample.java @@ -0,0 +1,82 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.analytics; + +/* Google Analytics Data API sample application demonstrating the usage of +metric aggregations in a report. + +See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.metric_aggregations +for more information. + +Before you start the application, please review the comments starting with +"TODO(developer)" and update the code to use correct values. + +To run this sample using Maven: + cd java-analytics-data/samples/snippets + mvn compile + mvn exec:java -Dexec.mainClass="com.example.analytics.RunReportWithAggregationsSample" + */ + +// [START analyticsdata_run_report_with_aggregations] +import com.google.analytics.data.v1beta.BetaAnalyticsDataClient; +import com.google.analytics.data.v1beta.DateRange; +import com.google.analytics.data.v1beta.Dimension; +import com.google.analytics.data.v1beta.Metric; +import com.google.analytics.data.v1beta.MetricAggregation; +import com.google.analytics.data.v1beta.RunReportRequest; +import com.google.analytics.data.v1beta.RunReportResponse; +import java.util.ArrayList; + +public class RunReportWithAggregationsSample { + + 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"; + sampleRunReportWithAggregations(propertyId); + } + + // Runs a report which includes total, maximum and minimum values for each metric. + static void sampleRunReportWithAggregations(String propertyId) throws Exception { + // Using a default constructor instructs the client to use the credentials + // specified in GOOGLE_APPLICATION_CREDENTIALS environment variable. + try (BetaAnalyticsDataClient analyticsData = BetaAnalyticsDataClient.create()) { + RunReportRequest request = + RunReportRequest.newBuilder() + .setProperty("properties/" + propertyId) + .addDimensions(Dimension.newBuilder().setName("country")) + .addMetrics(Metric.newBuilder().setName("sessions")) + .addDateRanges(DateRange.newBuilder().setStartDate("365daysAgo").setEndDate("today")) + .addAllMetricAggregations( + new ArrayList() { + { + add(MetricAggregation.TOTAL); + add(MetricAggregation.MAXIMUM); + add(MetricAggregation.MINIMUM); + } + }) + .build(); + + // Make the request. + RunReportResponse response = analyticsData.runReport(request); + RunReportSample.printRunResponseResponse(response); + } + } +} +// [END analyticsdata_run_report_with_aggregations] diff --git a/samples/snippets/src/main/java/com/example/analytics/RunReportWithCohortsSample.java b/samples/snippets/src/main/java/com/example/analytics/RunReportWithCohortsSample.java new file mode 100644 index 00000000..510aab60 --- /dev/null +++ b/samples/snippets/src/main/java/com/example/analytics/RunReportWithCohortsSample.java @@ -0,0 +1,97 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.analytics; + +/* Google Analytics Data API sample application demonstrating the usage of +cohort specification in a report. + +See +https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#body.request_body.FIELDS.cohort_spec +for more information. + +Before you start the application, please review the comments starting with +"TODO(developer)" and update the code to use correct values. + +To run this sample using Maven: + cd java-analytics-data/samples/snippets + mvn compile + mvn exec:java -Dexec.mainClass="com.example.analytics.RunReportWithCohortsSample" + */ + +// [START analyticsdata_run_report_with_cohorts] +import com.google.analytics.data.v1beta.BetaAnalyticsDataClient; +import com.google.analytics.data.v1beta.Cohort; +import com.google.analytics.data.v1beta.CohortSpec; +import com.google.analytics.data.v1beta.CohortsRange; +import com.google.analytics.data.v1beta.DateRange; +import com.google.analytics.data.v1beta.Dimension; +import com.google.analytics.data.v1beta.Metric; +import com.google.analytics.data.v1beta.RunReportRequest; +import com.google.analytics.data.v1beta.RunReportResponse; + +public class RunReportWithCohortsSample { + + 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"; + sampleRunReportWithCohorts(propertyId); + } + + // Runs a report on a cohort of users whose first session happened on the + // same week. The number of active users and user retention rate is calculated + // for the cohort using WEEKLY granularity. + static void sampleRunReportWithCohorts(String propertyId) throws Exception { + // Using a default constructor instructs the client to use the credentials + // specified in GOOGLE_APPLICATION_CREDENTIALS environment variable. + try (BetaAnalyticsDataClient analyticsData = BetaAnalyticsDataClient.create()) { + RunReportRequest request = + RunReportRequest.newBuilder() + .setProperty("properties/" + propertyId) + .addDimensions(Dimension.newBuilder().setName("cohort")) + .addDimensions(Dimension.newBuilder().setName("cohortNthWeek")) + .addMetrics(Metric.newBuilder().setName("cohortActiveUsers")) + .addMetrics( + Metric.newBuilder() + .setName("cohortRetentionRate") + .setExpression("cohortActiveUsers/cohortTotalUsers")) + .setCohortSpec( + CohortSpec.newBuilder() + .addCohorts( + Cohort.newBuilder() + .setDimension("firstSessionDate") + .setName("cohort") + .setDateRange( + DateRange.newBuilder() + .setStartDate("2021-01-03") + .setEndDate("2021-01-09"))) + .setCohortsRange( + CohortsRange.newBuilder() + .setStartOffset(0) + .setEndOffset(4) + .setGranularity(CohortsRange.Granularity.WEEKLY))) + .build(); + + // Make the request. + RunReportResponse response = analyticsData.runReport(request); + RunReportSample.printRunResponseResponse(response); + } + } +} +// [END analyticsdata_run_report_with_cohorts] diff --git a/samples/snippets/src/test/java/com/example/analytics/RunReportWithAggregationsSampleTest.java b/samples/snippets/src/test/java/com/example/analytics/RunReportWithAggregationsSampleTest.java new file mode 100644 index 00000000..566dbbb8 --- /dev/null +++ b/samples/snippets/src/test/java/com/example/analytics/RunReportWithAggregationsSampleTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.analytics; + +import static com.google.common.truth.Truth.assertThat; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for the RunReportWithAggregations sample. */ +@RunWith(JUnit4.class) +public class RunReportWithAggregationsSampleTest { + + private String ga4PropertyId = + System.getProperty("analyticsdata.quickstart.ga4PropertyId", "222596558"); + + private String runSample(String ga4PropertyId) throws Exception { + PrintStream stdOut = System.out; + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + PrintStream out = new PrintStream(bout); + System.setOut(out); + + // Run the test using default system credentials. + RunReportWithAggregationsSample.sampleRunReportWithAggregations(ga4PropertyId); + System.setOut(stdOut); + return bout.toString(); + } + + @Test + public void testRunReportWithAggregations() throws Exception { + // Act + String out = runSample(ga4PropertyId); + + // Assert + assertThat(out).contains("Report result:"); + } +} diff --git a/samples/snippets/src/test/java/com/example/analytics/RunReportWithCohortsSampleTest.java b/samples/snippets/src/test/java/com/example/analytics/RunReportWithCohortsSampleTest.java new file mode 100644 index 00000000..c018d4c7 --- /dev/null +++ b/samples/snippets/src/test/java/com/example/analytics/RunReportWithCohortsSampleTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.analytics; + +import static com.google.common.truth.Truth.assertThat; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for the RunReportWithCohorts sample. */ +@RunWith(JUnit4.class) +public class RunReportWithCohortsSampleTest { + + private String ga4PropertyId = + System.getProperty("analyticsdata.quickstart.ga4PropertyId", "222596558"); + + private String runSample(String ga4PropertyId) throws Exception { + PrintStream stdOut = System.out; + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + PrintStream out = new PrintStream(bout); + System.setOut(out); + + // Run the test using default system credentials. + RunReportWithCohortsSample.sampleRunReportWithCohorts(ga4PropertyId); + System.setOut(stdOut); + return bout.toString(); + } + + @Test + public void testRunReportWithCohorts() throws Exception { + // Act + String out = runSample(ga4PropertyId); + + // Assert + assertThat(out).contains("Report result:"); + } +} diff --git a/versions.txt b/versions.txt index 410d7d0d..99fc3526 100644 --- a/versions.txt +++ b/versions.txt @@ -1,6 +1,6 @@ # Format: # module:released-version:current-version -google-analytics-data:0.11.9:0.11.9 -grpc-google-analytics-data-v1beta:0.11.9:0.11.9 -proto-google-analytics-data-v1beta:0.11.9:0.11.9 +google-analytics-data:0.11.10:0.11.10 +grpc-google-analytics-data-v1beta:0.11.10:0.11.10 +proto-google-analytics-data-v1beta:0.11.10:0.11.10