xref: /aosp_15_r20/external/googleapis/google/cloud/recommendationengine/v1beta1/user_event.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2020 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.recommendationengine.v1beta1;
18
19import "google/api/field_behavior.proto";
20import "google/cloud/recommendationengine/v1beta1/catalog.proto";
21import "google/cloud/recommendationengine/v1beta1/common.proto";
22import "google/protobuf/timestamp.proto";
23
24option csharp_namespace = "Google.Cloud.RecommendationEngine.V1Beta1";
25option go_package = "cloud.google.com/go/recommendationengine/apiv1beta1/recommendationenginepb;recommendationenginepb";
26option java_multiple_files = true;
27option java_package = "com.google.cloud.recommendationengine.v1beta1";
28option objc_class_prefix = "RECAI";
29option php_namespace = "Google\\Cloud\\RecommendationEngine\\V1beta1";
30option ruby_package = "Google::Cloud::RecommendationEngine::V1beta1";
31
32// UserEvent captures all metadata information recommendation engine needs to
33// know about how end users interact with customers' website.
34message UserEvent {
35  // User event source.
36  enum EventSource {
37    // Unspecified event source.
38    EVENT_SOURCE_UNSPECIFIED = 0;
39
40    // The event is ingested via a javascript pixel or Recommendations AI Tag
41    // through automl datalayer or JS Macros.
42    AUTOML = 1;
43
44    // The event is ingested via Recommendations AI Tag through Enhanced
45    // Ecommerce datalayer.
46    ECOMMERCE = 2;
47
48    // The event is ingested via Import user events API.
49    BATCH_UPLOAD = 3;
50  }
51
52  // Required. User event type. Allowed values are:
53  //
54  // * `add-to-cart` Products being added to cart.
55  // * `add-to-list` Items being added to a list (shopping list, favorites
56  //   etc).
57  // * `category-page-view` Special pages such as sale or promotion pages
58  //   viewed.
59  // * `checkout-start` User starting a checkout process.
60  // * `detail-page-view` Products detail page viewed.
61  // * `home-page-view` Homepage viewed.
62  // * `page-visit` Generic page visits not included in the event types above.
63  // * `purchase-complete` User finishing a purchase.
64  // * `refund` Purchased items being refunded or returned.
65  // * `remove-from-cart` Products being removed from cart.
66  // * `remove-from-list` Items being removed from a list.
67  // * `search` Product search.
68  // * `shopping-cart-page-view` User viewing a shopping cart.
69  // * `impression` List of items displayed. Used by Google Tag Manager.
70  string event_type = 1 [(google.api.field_behavior) = REQUIRED];
71
72  // Required. User information.
73  UserInfo user_info = 2 [(google.api.field_behavior) = REQUIRED];
74
75  // Optional. User event detailed information common across different
76  // recommendation types.
77  EventDetail event_detail = 3 [(google.api.field_behavior) = OPTIONAL];
78
79  // Optional. Retail product specific user event metadata.
80  //
81  // This field is required for the following event types:
82  //
83  // * `add-to-cart`
84  // * `add-to-list`
85  // * `category-page-view`
86  // * `checkout-start`
87  // * `detail-page-view`
88  // * `purchase-complete`
89  // * `refund`
90  // * `remove-from-cart`
91  // * `remove-from-list`
92  // * `search`
93  //
94  // This field is optional for the following event types:
95  //
96  // * `page-visit`
97  // * `shopping-cart-page-view` - note that 'product_event_detail' should be
98  //   set for this unless the shopping cart is empty.
99  //
100  // This field is not allowed for the following event types:
101  //
102  // * `home-page-view`
103  ProductEventDetail product_event_detail = 4 [(google.api.field_behavior) = OPTIONAL];
104
105  // Optional. Only required for ImportUserEvents method. Timestamp of user
106  // event created.
107  google.protobuf.Timestamp event_time = 5 [(google.api.field_behavior) = OPTIONAL];
108
109  // Optional. This field should *not* be set when using JavaScript pixel
110  // or the Recommendations AI Tag. Defaults to `EVENT_SOURCE_UNSPECIFIED`.
111  EventSource event_source = 6 [(google.api.field_behavior) = OPTIONAL];
112}
113
114// Information of end users.
115message UserInfo {
116  // Required. A unique identifier for tracking visitors with a length limit of
117  // 128 bytes.
118  //
119  // For example, this could be implemented with a http cookie, which should be
120  // able to uniquely identify a visitor on a single device. This unique
121  // identifier should not change if the visitor log in/out of the website.
122  // Maximum length 128 bytes. Cannot be empty.
123  string visitor_id = 1 [(google.api.field_behavior) = REQUIRED];
124
125  // Optional. Unique identifier for logged-in user with a length limit of 128
126  // bytes. Required only for logged-in users.
127  string user_id = 2 [(google.api.field_behavior) = OPTIONAL];
128
129  // Optional. IP address of the user. This could be either IPv4 (e.g. 104.133.9.80) or
130  // IPv6 (e.g. 2001:0db8:85a3:0000:0000:8a2e:0370:7334). This should *not* be
131  // set when using the javascript pixel or if `direct_user_request` is set.
132  // Used to extract location information for personalization.
133  string ip_address = 3 [(google.api.field_behavior) = OPTIONAL];
134
135  // Optional. User agent as included in the HTTP header. UTF-8 encoded string
136  // with a length limit of 1 KiB.
137  //
138  // This should *not* be set when using the JavaScript pixel or if
139  // `directUserRequest` is set.
140  string user_agent = 4 [(google.api.field_behavior) = OPTIONAL];
141
142  // Optional. Indicates if the request is made directly from the end user
143  // in which case the user_agent and ip_address fields can be populated
144  // from the HTTP request. This should *not* be set when using the javascript
145  // pixel. This flag should be set only if the API request is made directly
146  // from the end user such as a mobile app (and not if a gateway or a server is
147  // processing and pushing the user events).
148  bool direct_user_request = 5 [(google.api.field_behavior) = OPTIONAL];
149}
150
151// User event details shared by all recommendation types.
152message EventDetail {
153  // Optional. Complete url (window.location.href) of the user's current page.
154  // When using the JavaScript pixel, this value is filled in automatically.
155  // Maximum length 5KB.
156  string uri = 1 [(google.api.field_behavior) = OPTIONAL];
157
158  // Optional. The referrer url of the current page. When using
159  // the JavaScript pixel, this value is filled in automatically.
160  string referrer_uri = 6 [(google.api.field_behavior) = OPTIONAL];
161
162  // Optional. A unique id of a web page view.
163  // This should be kept the same for all user events triggered from the same
164  // pageview. For example, an item detail page view could trigger multiple
165  // events as the user is browsing the page.
166  // The `pageViewId` property should be kept the same for all these events so
167  // that they can be grouped together properly. This `pageViewId` will be
168  // automatically generated if using the JavaScript pixel.
169  string page_view_id = 2 [(google.api.field_behavior) = OPTIONAL];
170
171  // Optional. A list of identifiers for the independent experiment groups
172  // this user event belongs to. This is used to distinguish between user events
173  // associated with different experiment setups (e.g. using Recommendation
174  // Engine system, using different recommendation models).
175  repeated string experiment_ids = 3 [(google.api.field_behavior) = OPTIONAL];
176
177  // Optional. Recommendation token included in the recommendation prediction
178  // response.
179  //
180  // This field enables accurate attribution of recommendation model
181  // performance.
182  //
183  // This token enables us to accurately attribute page view or purchase back to
184  // the event and the particular predict response containing this
185  // clicked/purchased item. If user clicks on product K in the recommendation
186  // results, pass the `PredictResponse.recommendationToken` property as a url
187  // parameter to product K's page. When recording events on product K's page,
188  // log the PredictResponse.recommendation_token to this field.
189  //
190  // Optional, but highly encouraged for user events that are the result of a
191  // recommendation prediction query.
192  string recommendation_token = 4 [(google.api.field_behavior) = OPTIONAL];
193
194  // Optional. Extra user event features to include in the recommendation
195  // model.
196  //
197  // For product recommendation, an example of extra user information is
198  // traffic_channel, i.e. how user arrives at the site. Users can arrive
199  // at the site by coming to the site directly, or coming through Google
200  // search, and etc.
201  FeatureMap event_attributes = 5 [(google.api.field_behavior) = OPTIONAL];
202}
203
204// ProductEventDetail captures user event information specific to retail
205// products.
206message ProductEventDetail {
207  // Required for `search` events. Other event types should not set this field.
208  // The user's search query as UTF-8 encoded text with a length limit of 5 KiB.
209  string search_query = 1;
210
211  // Required for `category-page-view` events. Other event types should not set
212  // this field.
213  // The categories associated with a category page.
214  // Category pages include special pages such as sales or promotions. For
215  // instance, a special sale page may have the category hierarchy:
216  // categories : ["Sales", "2017 Black Friday Deals"].
217  repeated CatalogItem.CategoryHierarchy page_categories = 2;
218
219  // The main product details related to the event.
220  //
221  // This field is required for the following event types:
222  //
223  // * `add-to-cart`
224  // * `add-to-list`
225  // * `checkout-start`
226  // * `detail-page-view`
227  // * `purchase-complete`
228  // * `refund`
229  // * `remove-from-cart`
230  // * `remove-from-list`
231  //
232  // This field is optional for the following event types:
233  //
234  // * `page-visit`
235  // * `shopping-cart-page-view` - note that 'product_details' should be set for
236  //   this unless the shopping cart is empty.
237  //
238  // This field is not allowed for the following event types:
239  //
240  // * `category-page-view`
241  // * `home-page-view`
242  // * `search`
243  repeated ProductDetail product_details = 3;
244
245  // Required for `add-to-list` and `remove-from-list` events. The id or name of
246  // the list that the item is being added to or removed from. Other event types
247  // should not set this field.
248  string list_id = 4;
249
250  // Optional. The id or name of the associated shopping cart. This id is used
251  // to associate multiple items added or present in the cart before purchase.
252  //
253  // This can only be set for `add-to-cart`, `remove-from-cart`,
254  // `checkout-start`, `purchase-complete`, or `shopping-cart-page-view` events.
255  string cart_id = 5 [(google.api.field_behavior) = OPTIONAL];
256
257  // Optional. A transaction represents the entire purchase transaction.
258  // Required for `purchase-complete` events. Optional for `checkout-start`
259  // events. Other event types should not set this field.
260  PurchaseTransaction purchase_transaction = 6 [(google.api.field_behavior) = OPTIONAL];
261}
262
263// A transaction represents the entire purchase transaction.
264message PurchaseTransaction {
265  // Optional. The transaction ID with a length limit of 128 bytes.
266  string id = 1 [(google.api.field_behavior) = OPTIONAL];
267
268  // Required. Total revenue or grand total associated with the transaction.
269  // This value include shipping, tax, or other adjustments to total revenue
270  // that you want to include as part of your revenue calculations. This field
271  // is not required if the event type is `refund`.
272  float revenue = 2 [(google.api.field_behavior) = REQUIRED];
273
274  // Optional. All the taxes associated with the transaction.
275  map<string, float> taxes = 3 [(google.api.field_behavior) = OPTIONAL];
276
277  // Optional. All the costs associated with the product. These can be
278  // manufacturing costs, shipping expenses not borne by the end user, or any
279  // other costs.
280  //
281  // Total product cost such that
282  //   profit = revenue - (sum(taxes) + sum(costs))
283  // If product_cost is not set, then
284  //   profit = revenue - tax - shipping - sum(CatalogItem.costs).
285  //
286  // If CatalogItem.cost is not specified for one of the items, CatalogItem.cost
287  // based profit *cannot* be calculated for this Transaction.
288  map<string, float> costs = 4 [(google.api.field_behavior) = OPTIONAL];
289
290  // Required. Currency code. Use three-character ISO-4217 code. This field
291  // is not required if the event type is `refund`.
292  string currency_code = 6 [(google.api.field_behavior) = REQUIRED];
293}
294
295// Detailed product information associated with a user event.
296message ProductDetail {
297  // Required. Catalog item ID. UTF-8 encoded string with a length limit of 128
298  // characters.
299  string id = 1 [(google.api.field_behavior) = REQUIRED];
300
301  // Optional. Currency code for price/costs. Use three-character ISO-4217
302  // code. Required only if originalPrice or displayPrice is set.
303  string currency_code = 2 [(google.api.field_behavior) = OPTIONAL];
304
305  // Optional. Original price of the product. If provided, this will override
306  // the original price in Catalog for this product.
307  float original_price = 3 [(google.api.field_behavior) = OPTIONAL];
308
309  // Optional. Display price of the product (e.g. discounted price). If
310  // provided, this will override the display price in Catalog for this product.
311  float display_price = 4 [(google.api.field_behavior) = OPTIONAL];
312
313  // Optional. Item stock state. If provided, this overrides the stock state
314  // in Catalog for items in this event.
315  ProductCatalogItem.StockState stock_state = 5 [(google.api.field_behavior) = OPTIONAL];
316
317  // Optional. Quantity of the product associated with the user event. For
318  // example, this field will be 2 if two products are added to the shopping
319  // cart for `add-to-cart` event. Required for `add-to-cart`, `add-to-list`,
320  // `remove-from-cart`, `checkout-start`, `purchase-complete`, `refund` event
321  // types.
322  int32 quantity = 6 [(google.api.field_behavior) = OPTIONAL];
323
324  // Optional. Quantity of the products in stock when a user event happens.
325  // Optional. If provided, this overrides the available quantity in Catalog for
326  // this event. and can only be set if `stock_status` is set to `IN_STOCK`.
327  //
328  // Note that if an item is out of stock, you must set the `stock_state` field
329  // to be `OUT_OF_STOCK`. Leaving this field unspecified / as zero is not
330  // sufficient to mark the item out of stock.
331  int32 available_quantity = 7 [(google.api.field_behavior) = OPTIONAL];
332
333  // Optional. Extra features associated with a product in the user event.
334  FeatureMap item_attributes = 8 [(google.api.field_behavior) = OPTIONAL];
335}
336