1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.analytics.data.v1alpha; 18 19 import com.google.analytics.data.v1alpha.stub.AlphaAnalyticsDataStub; 20 import com.google.analytics.data.v1alpha.stub.AlphaAnalyticsDataStubSettings; 21 import com.google.api.core.BetaApi; 22 import com.google.api.gax.core.BackgroundResource; 23 import com.google.api.gax.rpc.UnaryCallable; 24 import java.io.IOException; 25 import java.util.concurrent.TimeUnit; 26 import javax.annotation.Generated; 27 28 // AUTO-GENERATED DOCUMENTATION AND CLASS. 29 /** 30 * Service Description: Google Analytics reporting data service. 31 * 32 * <p>This class provides the ability to make remote calls to the backing service through method 33 * calls that map to API methods. Sample code to get started: 34 * 35 * <pre>{@code 36 * // This snippet has been automatically generated and should be regarded as a code template only. 37 * // It will require modifications to work: 38 * // - It may require correct/in-range values for request initialization. 39 * // - It may require specifying regional endpoints when creating the service client as shown in 40 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 41 * try (AlphaAnalyticsDataClient alphaAnalyticsDataClient = AlphaAnalyticsDataClient.create()) { 42 * RunFunnelReportRequest request = 43 * RunFunnelReportRequest.newBuilder() 44 * .setProperty("property-993141291") 45 * .addAllDateRanges(new ArrayList<DateRange>()) 46 * .setFunnel(Funnel.newBuilder().build()) 47 * .setFunnelBreakdown(FunnelBreakdown.newBuilder().build()) 48 * .setFunnelNextAction(FunnelNextAction.newBuilder().build()) 49 * .addAllSegments(new ArrayList<Segment>()) 50 * .setLimit(102976443) 51 * .setDimensionFilter(FilterExpression.newBuilder().build()) 52 * .setReturnPropertyQuota(true) 53 * .build(); 54 * RunFunnelReportResponse response = alphaAnalyticsDataClient.runFunnelReport(request); 55 * } 56 * }</pre> 57 * 58 * <p>Note: close() needs to be called on the AlphaAnalyticsDataClient object to clean up resources 59 * such as threads. In the example above, try-with-resources is used, which automatically calls 60 * close(). 61 * 62 * <p>The surface of this class includes several types of Java methods for each of the API's 63 * methods: 64 * 65 * <ol> 66 * <li>A "flattened" method. With this type of method, the fields of the request type have been 67 * converted into function parameters. It may be the case that not all fields are available as 68 * parameters, and not every API method will have a flattened method entry point. 69 * <li>A "request object" method. This type of method only takes one parameter, a request object, 70 * which must be constructed before the call. Not every API method will have a request object 71 * method. 72 * <li>A "callable" method. This type of method takes no parameters and returns an immutable API 73 * callable object, which can be used to initiate calls to the service. 74 * </ol> 75 * 76 * <p>See the individual methods for example code. 77 * 78 * <p>Many parameters require resource names to be formatted in a particular way. To assist with 79 * these names, this class includes a format method for each type of name, and additionally a parse 80 * method to extract the individual identifiers contained within names that are returned. 81 * 82 * <p>This class can be customized by passing in a custom instance of AlphaAnalyticsDataSettings to 83 * create(). For example: 84 * 85 * <p>To customize credentials: 86 * 87 * <pre>{@code 88 * // This snippet has been automatically generated and should be regarded as a code template only. 89 * // It will require modifications to work: 90 * // - It may require correct/in-range values for request initialization. 91 * // - It may require specifying regional endpoints when creating the service client as shown in 92 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 93 * AlphaAnalyticsDataSettings alphaAnalyticsDataSettings = 94 * AlphaAnalyticsDataSettings.newBuilder() 95 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 96 * .build(); 97 * AlphaAnalyticsDataClient alphaAnalyticsDataClient = 98 * AlphaAnalyticsDataClient.create(alphaAnalyticsDataSettings); 99 * }</pre> 100 * 101 * <p>To customize the endpoint: 102 * 103 * <pre>{@code 104 * // This snippet has been automatically generated and should be regarded as a code template only. 105 * // It will require modifications to work: 106 * // - It may require correct/in-range values for request initialization. 107 * // - It may require specifying regional endpoints when creating the service client as shown in 108 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 109 * AlphaAnalyticsDataSettings alphaAnalyticsDataSettings = 110 * AlphaAnalyticsDataSettings.newBuilder().setEndpoint(myEndpoint).build(); 111 * AlphaAnalyticsDataClient alphaAnalyticsDataClient = 112 * AlphaAnalyticsDataClient.create(alphaAnalyticsDataSettings); 113 * }</pre> 114 * 115 * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over 116 * the wire: 117 * 118 * <pre>{@code 119 * // This snippet has been automatically generated and should be regarded as a code template only. 120 * // It will require modifications to work: 121 * // - It may require correct/in-range values for request initialization. 122 * // - It may require specifying regional endpoints when creating the service client as shown in 123 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 124 * AlphaAnalyticsDataSettings alphaAnalyticsDataSettings = 125 * AlphaAnalyticsDataSettings.newHttpJsonBuilder().build(); 126 * AlphaAnalyticsDataClient alphaAnalyticsDataClient = 127 * AlphaAnalyticsDataClient.create(alphaAnalyticsDataSettings); 128 * }</pre> 129 * 130 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 131 */ 132 @BetaApi 133 @Generated("by gapic-generator-java") 134 public class AlphaAnalyticsDataClient implements BackgroundResource { 135 private final AlphaAnalyticsDataSettings settings; 136 private final AlphaAnalyticsDataStub stub; 137 138 /** Constructs an instance of AlphaAnalyticsDataClient with default settings. */ create()139 public static final AlphaAnalyticsDataClient create() throws IOException { 140 return create(AlphaAnalyticsDataSettings.newBuilder().build()); 141 } 142 143 /** 144 * Constructs an instance of AlphaAnalyticsDataClient, using the given settings. The channels are 145 * created based on the settings passed in, or defaults for any settings that are not set. 146 */ create(AlphaAnalyticsDataSettings settings)147 public static final AlphaAnalyticsDataClient create(AlphaAnalyticsDataSettings settings) 148 throws IOException { 149 return new AlphaAnalyticsDataClient(settings); 150 } 151 152 /** 153 * Constructs an instance of AlphaAnalyticsDataClient, using the given stub for making calls. This 154 * is for advanced usage - prefer using create(AlphaAnalyticsDataSettings). 155 */ create(AlphaAnalyticsDataStub stub)156 public static final AlphaAnalyticsDataClient create(AlphaAnalyticsDataStub stub) { 157 return new AlphaAnalyticsDataClient(stub); 158 } 159 160 /** 161 * Constructs an instance of AlphaAnalyticsDataClient, using the given settings. This is protected 162 * so that it is easy to make a subclass, but otherwise, the static factory methods should be 163 * preferred. 164 */ AlphaAnalyticsDataClient(AlphaAnalyticsDataSettings settings)165 protected AlphaAnalyticsDataClient(AlphaAnalyticsDataSettings settings) throws IOException { 166 this.settings = settings; 167 this.stub = ((AlphaAnalyticsDataStubSettings) settings.getStubSettings()).createStub(); 168 } 169 AlphaAnalyticsDataClient(AlphaAnalyticsDataStub stub)170 protected AlphaAnalyticsDataClient(AlphaAnalyticsDataStub stub) { 171 this.settings = null; 172 this.stub = stub; 173 } 174 getSettings()175 public final AlphaAnalyticsDataSettings getSettings() { 176 return settings; 177 } 178 getStub()179 public AlphaAnalyticsDataStub getStub() { 180 return stub; 181 } 182 183 // AUTO-GENERATED DOCUMENTATION AND METHOD. 184 /** 185 * Returns a customized funnel report of your Google Analytics event data. The data returned from 186 * the API is as a table with columns for the requested dimensions and metrics. 187 * 188 * <p>Funnel exploration lets you visualize the steps your users take to complete a task and 189 * quickly see how well they are succeeding or failing at each step. For example, how do prospects 190 * become shoppers and then become buyers? How do one time buyers become repeat buyers? With this 191 * information, you can improve inefficient or abandoned customer journeys. To learn more, see 192 * [GA4 Funnel Explorations](https://support.google.com/analytics/answer/9327974). 193 * 194 * <p>Sample code: 195 * 196 * <pre>{@code 197 * // This snippet has been automatically generated and should be regarded as a code template only. 198 * // It will require modifications to work: 199 * // - It may require correct/in-range values for request initialization. 200 * // - It may require specifying regional endpoints when creating the service client as shown in 201 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 202 * try (AlphaAnalyticsDataClient alphaAnalyticsDataClient = AlphaAnalyticsDataClient.create()) { 203 * RunFunnelReportRequest request = 204 * RunFunnelReportRequest.newBuilder() 205 * .setProperty("property-993141291") 206 * .addAllDateRanges(new ArrayList<DateRange>()) 207 * .setFunnel(Funnel.newBuilder().build()) 208 * .setFunnelBreakdown(FunnelBreakdown.newBuilder().build()) 209 * .setFunnelNextAction(FunnelNextAction.newBuilder().build()) 210 * .addAllSegments(new ArrayList<Segment>()) 211 * .setLimit(102976443) 212 * .setDimensionFilter(FilterExpression.newBuilder().build()) 213 * .setReturnPropertyQuota(true) 214 * .build(); 215 * RunFunnelReportResponse response = alphaAnalyticsDataClient.runFunnelReport(request); 216 * } 217 * }</pre> 218 * 219 * @param request The request object containing all of the parameters for the API call. 220 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 221 */ runFunnelReport(RunFunnelReportRequest request)222 public final RunFunnelReportResponse runFunnelReport(RunFunnelReportRequest request) { 223 return runFunnelReportCallable().call(request); 224 } 225 226 // AUTO-GENERATED DOCUMENTATION AND METHOD. 227 /** 228 * Returns a customized funnel report of your Google Analytics event data. The data returned from 229 * the API is as a table with columns for the requested dimensions and metrics. 230 * 231 * <p>Funnel exploration lets you visualize the steps your users take to complete a task and 232 * quickly see how well they are succeeding or failing at each step. For example, how do prospects 233 * become shoppers and then become buyers? How do one time buyers become repeat buyers? With this 234 * information, you can improve inefficient or abandoned customer journeys. To learn more, see 235 * [GA4 Funnel Explorations](https://support.google.com/analytics/answer/9327974). 236 * 237 * <p>Sample code: 238 * 239 * <pre>{@code 240 * // This snippet has been automatically generated and should be regarded as a code template only. 241 * // It will require modifications to work: 242 * // - It may require correct/in-range values for request initialization. 243 * // - It may require specifying regional endpoints when creating the service client as shown in 244 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 245 * try (AlphaAnalyticsDataClient alphaAnalyticsDataClient = AlphaAnalyticsDataClient.create()) { 246 * RunFunnelReportRequest request = 247 * RunFunnelReportRequest.newBuilder() 248 * .setProperty("property-993141291") 249 * .addAllDateRanges(new ArrayList<DateRange>()) 250 * .setFunnel(Funnel.newBuilder().build()) 251 * .setFunnelBreakdown(FunnelBreakdown.newBuilder().build()) 252 * .setFunnelNextAction(FunnelNextAction.newBuilder().build()) 253 * .addAllSegments(new ArrayList<Segment>()) 254 * .setLimit(102976443) 255 * .setDimensionFilter(FilterExpression.newBuilder().build()) 256 * .setReturnPropertyQuota(true) 257 * .build(); 258 * ApiFuture<RunFunnelReportResponse> future = 259 * alphaAnalyticsDataClient.runFunnelReportCallable().futureCall(request); 260 * // Do something. 261 * RunFunnelReportResponse response = future.get(); 262 * } 263 * }</pre> 264 */ 265 public final UnaryCallable<RunFunnelReportRequest, RunFunnelReportResponse> runFunnelReportCallable()266 runFunnelReportCallable() { 267 return stub.runFunnelReportCallable(); 268 } 269 270 @Override close()271 public final void close() { 272 stub.close(); 273 } 274 275 @Override shutdown()276 public void shutdown() { 277 stub.shutdown(); 278 } 279 280 @Override isShutdown()281 public boolean isShutdown() { 282 return stub.isShutdown(); 283 } 284 285 @Override isTerminated()286 public boolean isTerminated() { 287 return stub.isTerminated(); 288 } 289 290 @Override shutdownNow()291 public void shutdownNow() { 292 stub.shutdownNow(); 293 } 294 295 @Override awaitTermination(long duration, TimeUnit unit)296 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 297 return stub.awaitTermination(duration, unit); 298 } 299 } 300