1// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package google.cloud.retail.v2;
18
19import "google/api/field_behavior.proto";
20import "google/cloud/retail/v2/common.proto";
21import "google/cloud/retail/v2/product.proto";
22import "google/protobuf/timestamp.proto";
23import "google/protobuf/wrappers.proto";
24
25option csharp_namespace = "Google.Cloud.Retail.V2";
26option go_package = "cloud.google.com/go/retail/apiv2/retailpb;retailpb";
27option java_multiple_files = true;
28option java_outer_classname = "UserEventProto";
29option java_package = "com.google.cloud.retail.v2";
30option objc_class_prefix = "RETAIL";
31option php_namespace = "Google\\Cloud\\Retail\\V2";
32option ruby_package = "Google::Cloud::Retail::V2";
33
34// UserEvent captures all metadata information Retail API needs to know about
35// how end users interact with customers' website.
36message UserEvent {
37  // Required. User event type. Allowed values are:
38  //
39  // * `add-to-cart`: Products being added to cart.
40  // * `category-page-view`: Special pages such as sale or promotion pages
41  //   viewed.
42  // * `detail-page-view`: Products detail page viewed.
43  // * `home-page-view`: Homepage viewed.
44  // * `promotion-offered`: Promotion is offered to a user.
45  // * `promotion-not-offered`: Promotion is not offered to a user.
46  // * `purchase-complete`: User finishing a purchase.
47  // * `search`: Product search.
48  // * `shopping-cart-page-view`: User viewing a shopping cart.
49  string event_type = 1 [(google.api.field_behavior) = REQUIRED];
50
51  // Required. A unique identifier for tracking visitors.
52  //
53  // For example, this could be implemented with an HTTP cookie, which should be
54  // able to uniquely identify a visitor on a single device. This unique
55  // identifier should not change if the visitor log in/out of the website.
56  //
57  // Don't set the field to the same fixed ID for different users. This mixes
58  // the event history of those users together, which results in degraded model
59  // quality.
60  //
61  // The field must be a UTF-8 encoded string with a length limit of 128
62  // characters. Otherwise, an INVALID_ARGUMENT error is returned.
63  //
64  // The field should not contain PII or user-data. We recommend to use Google
65  // Analytics [Client
66  // ID](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#clientId)
67  // for this field.
68  string visitor_id = 2 [(google.api.field_behavior) = REQUIRED];
69
70  // A unique identifier for tracking a visitor session with a length limit of
71  // 128 bytes. A session is an aggregation of an end user behavior in a time
72  // span.
73  //
74  // A general guideline to populate the sesion_id:
75  // 1. If user has no activity for 30 min, a new session_id should be assigned.
76  // 2. The session_id should be unique across users, suggest use uuid or add
77  // visitor_id as prefix.
78  string session_id = 21;
79
80  // Only required for
81  // [UserEventService.ImportUserEvents][google.cloud.retail.v2.UserEventService.ImportUserEvents]
82  // method. Timestamp of when the user event happened.
83  google.protobuf.Timestamp event_time = 3;
84
85  // A list of identifiers for the independent experiment groups this user event
86  // belongs to. This is used to distinguish between user events associated with
87  // different experiment setups (e.g. using Retail API, using different
88  // recommendation models).
89  repeated string experiment_ids = 4;
90
91  // Highly recommended for user events that are the result of
92  // [PredictionService.Predict][google.cloud.retail.v2.PredictionService.Predict].
93  // This field enables accurate attribution of recommendation model
94  // performance.
95  //
96  // The value must be a valid
97  // [PredictResponse.attribution_token][google.cloud.retail.v2.PredictResponse.attribution_token]
98  // for user events that are the result of
99  // [PredictionService.Predict][google.cloud.retail.v2.PredictionService.Predict].
100  // The value must be a valid
101  // [SearchResponse.attribution_token][google.cloud.retail.v2.SearchResponse.attribution_token]
102  // for user events that are the result of
103  // [SearchService.Search][google.cloud.retail.v2.SearchService.Search].
104  //
105  // This token enables us to accurately attribute page view or purchase back to
106  // the event and the particular predict response containing this
107  // clicked/purchased product. If user clicks on product K in the
108  // recommendation results, pass
109  // [PredictResponse.attribution_token][google.cloud.retail.v2.PredictResponse.attribution_token]
110  // as a URL parameter to product K's page. When recording events on product
111  // K's page, log the
112  // [PredictResponse.attribution_token][google.cloud.retail.v2.PredictResponse.attribution_token]
113  // to this field.
114  string attribution_token = 5;
115
116  // The main product details related to the event.
117  //
118  // This field is optional except for the following event types:
119  //
120  // * `add-to-cart`
121  // * `detail-page-view`
122  // * `purchase-complete`
123  //
124  // In a `search` event, this field represents the products returned to the end
125  // user on the current page (the end user may have not finished browsing the
126  // whole page yet). When a new page is returned to the end user, after
127  // pagination/filtering/ordering even for the same query, a new `search` event
128  // with different
129  // [product_details][google.cloud.retail.v2.UserEvent.product_details] is
130  // desired. The end user may have not finished browsing the whole page yet.
131  repeated ProductDetail product_details = 6;
132
133  // The main auto-completion details related to the event.
134  //
135  // This field should be set for `search` event when autocomplete function is
136  // enabled and the user clicks a suggestion for search.
137  CompletionDetail completion_detail = 22;
138
139  // Extra user event features to include in the recommendation model.
140  //
141  // If you provide custom attributes for ingested user events, also include
142  // them in the user events that you associate with prediction requests. Custom
143  // attribute formatting must be consistent between imported events and events
144  // provided with prediction requests. This lets the Retail API use
145  // those custom attributes when training models and serving predictions, which
146  // helps improve recommendation quality.
147  //
148  // This field needs to pass all below criteria, otherwise an INVALID_ARGUMENT
149  // error is returned:
150  //
151  // * The key must be a UTF-8 encoded string with a length limit of 5,000
152  //   characters.
153  // * For text attributes, at most 400 values are allowed. Empty values are not
154  //   allowed. Each value must be a UTF-8 encoded string with a length limit of
155  //   256 characters.
156  // * For number attributes, at most 400 values are allowed.
157  //
158  // For product recommendations, an example of extra user information is
159  // traffic_channel, which is how a user arrives at the site. Users can arrive
160  // at the site by coming to the site directly, coming through Google
161  // search, or in other ways.
162  map<string, CustomAttribute> attributes = 7;
163
164  // The ID or name of the associated shopping cart. This ID is used
165  // to associate multiple items added or present in the cart before purchase.
166  //
167  // This can only be set for `add-to-cart`, `purchase-complete`, or
168  // `shopping-cart-page-view` events.
169  string cart_id = 8;
170
171  // A transaction represents the entire purchase transaction.
172  //
173  // Required for `purchase-complete` events. Other event types should not set
174  // this field. Otherwise, an INVALID_ARGUMENT error is returned.
175  PurchaseTransaction purchase_transaction = 9;
176
177  // The user's search query.
178  //
179  // See [SearchRequest.query][google.cloud.retail.v2.SearchRequest.query] for
180  // definition.
181  //
182  // The value must be a UTF-8 encoded string with a length limit of 5,000
183  // characters. Otherwise, an INVALID_ARGUMENT error is returned.
184  //
185  // At least one of
186  // [search_query][google.cloud.retail.v2.UserEvent.search_query] or
187  // [page_categories][google.cloud.retail.v2.UserEvent.page_categories] is
188  // required for `search` events. Other event types should not set this field.
189  // Otherwise, an INVALID_ARGUMENT error is returned.
190  string search_query = 10;
191
192  // The filter syntax consists of an expression language for constructing a
193  // predicate from one or more fields of the products being filtered.
194  //
195  // See [SearchRequest.filter][google.cloud.retail.v2.SearchRequest.filter] for
196  // definition and syntax.
197  //
198  // The value must be a UTF-8 encoded string with a length limit of 1,000
199  // characters. Otherwise, an INVALID_ARGUMENT error is returned.
200  string filter = 16;
201
202  // The order in which products are returned.
203  //
204  // See [SearchRequest.order_by][google.cloud.retail.v2.SearchRequest.order_by]
205  // for definition and syntax.
206  //
207  // The value must be a UTF-8 encoded string with a length limit of 1,000
208  // characters. Otherwise, an INVALID_ARGUMENT error is returned.
209  //
210  // This can only be set for `search` events. Other event types should not set
211  // this field. Otherwise, an INVALID_ARGUMENT error is returned.
212  string order_by = 17;
213
214  // An integer that specifies the current offset for pagination (the 0-indexed
215  // starting location, amongst the products deemed by the API as relevant).
216  //
217  // See [SearchRequest.offset][google.cloud.retail.v2.SearchRequest.offset] for
218  // definition.
219  //
220  // If this field is negative, an INVALID_ARGUMENT is returned.
221  //
222  // This can only be set for `search` events. Other event types should not set
223  // this field. Otherwise, an INVALID_ARGUMENT error is returned.
224  int32 offset = 18;
225
226  // The categories associated with a category page.
227  //
228  // To represent full path of category, use '>' sign to separate different
229  // hierarchies. If '>' is part of the category name, replace it with
230  // other character(s).
231  //
232  // Category pages include special pages such as sales or promotions. For
233  // instance, a special sale page may have the category hierarchy:
234  // "pageCategories" : ["Sales > 2017 Black Friday Deals"].
235  //
236  // Required for `category-page-view` events. At least one of
237  // [search_query][google.cloud.retail.v2.UserEvent.search_query] or
238  // [page_categories][google.cloud.retail.v2.UserEvent.page_categories] is
239  // required for `search` events. Other event types should not set this field.
240  // Otherwise, an INVALID_ARGUMENT error is returned.
241  repeated string page_categories = 11;
242
243  // User information.
244  UserInfo user_info = 12;
245
246  // Complete URL (window.location.href) of the user's current page.
247  //
248  // When using the client side event reporting with JavaScript pixel and Google
249  // Tag Manager, this value is filled in automatically. Maximum length 5,000
250  // characters.
251  string uri = 13;
252
253  // The referrer URL of the current page.
254  //
255  // When using the client side event reporting with JavaScript pixel and Google
256  // Tag Manager, this value is filled in automatically.
257  string referrer_uri = 14;
258
259  // A unique ID of a web page view.
260  //
261  // This should be kept the same for all user events triggered from the same
262  // pageview. For example, an item detail page view could trigger multiple
263  // events as the user is browsing the page. The `pageViewId` property should
264  // be kept the same for all these events so that they can be grouped together
265  // properly.
266  //
267  // When using the client side event reporting with JavaScript pixel and Google
268  // Tag Manager, this value is filled in automatically.
269  string page_view_id = 15;
270
271  // The entity for customers that may run multiple different entities, domains,
272  // sites or regions, for example, `Google US`, `Google Ads`, `Waymo`,
273  // `google.com`, `youtube.com`, etc.
274  // It is recommended to set this field to get better per-entity search,
275  // completion and prediction results.
276  string entity = 23;
277}
278
279// Detailed product information associated with a user event.
280message ProductDetail {
281  // Required. [Product][google.cloud.retail.v2.Product] information.
282  //
283  // Required field(s):
284  //
285  // * [Product.id][google.cloud.retail.v2.Product.id]
286  //
287  // Optional override field(s):
288  //
289  // * [Product.price_info][google.cloud.retail.v2.Product.price_info]
290  //
291  // If any supported optional fields are provided, we will treat them as a full
292  // override when looking up product information from the catalog. Thus, it is
293  // important to ensure that the overriding fields are accurate and
294  // complete.
295  //
296  // All other product fields are ignored and instead populated via catalog
297  // lookup after event ingestion.
298  Product product = 1 [(google.api.field_behavior) = REQUIRED];
299
300  // Quantity of the product associated with the user event.
301  //
302  // For example, this field will be 2 if two products are added to the shopping
303  // cart for `purchase-complete` event. Required for `add-to-cart` and
304  // `purchase-complete` event types.
305  google.protobuf.Int32Value quantity = 2;
306}
307
308// Detailed completion information including completion attribution token and
309// clicked completion info.
310message CompletionDetail {
311  // Completion attribution token in
312  // [CompleteQueryResponse.attribution_token][google.cloud.retail.v2.CompleteQueryResponse.attribution_token].
313  string completion_attribution_token = 1;
314
315  // End user selected
316  // [CompleteQueryResponse.CompletionResult.suggestion][google.cloud.retail.v2.CompleteQueryResponse.CompletionResult.suggestion].
317  string selected_suggestion = 2;
318
319  // End user selected
320  // [CompleteQueryResponse.CompletionResult.suggestion][google.cloud.retail.v2.CompleteQueryResponse.CompletionResult.suggestion]
321  // position, starting from 0.
322  int32 selected_position = 3;
323}
324
325// A transaction represents the entire purchase transaction.
326message PurchaseTransaction {
327  // The transaction ID with a length limit of 128 characters.
328  string id = 1;
329
330  // Required. Total non-zero revenue or grand total associated with the
331  // transaction. This value include shipping, tax, or other adjustments to
332  // total revenue that you want to include as part of your revenue
333  // calculations.
334  float revenue = 2 [(google.api.field_behavior) = REQUIRED];
335
336  // All the taxes associated with the transaction.
337  float tax = 3;
338
339  // All the costs associated with the products. These can be manufacturing
340  // costs, shipping expenses not borne by the end user, or any other costs,
341  // such that:
342  //
343  // * Profit = [revenue][google.cloud.retail.v2.PurchaseTransaction.revenue] -
344  // [tax][google.cloud.retail.v2.PurchaseTransaction.tax] -
345  // [cost][google.cloud.retail.v2.PurchaseTransaction.cost]
346  float cost = 4;
347
348  // Required. Currency code. Use three-character ISO-4217 code.
349  string currency_code = 5 [(google.api.field_behavior) = REQUIRED];
350}
351