user_event.proto 15 KB

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