user_event.proto 15 KB

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