Writes a single user event.

Scopes

You will need authorization for the https://www.googleapis.com/auth/cloud-platform scope to make a valid call.

If unset, the scope for this method defaults to https://www.googleapis.com/auth/cloud-platform. You can set the scope for this method like this: retail2 --scope <scope> projects locations-catalogs-user-events-write ...

Required Scalar Argument

  • <parent> (string)
    • Required. The parent catalog resource name, such as projects/1234/locations/global/catalogs/default_catalog.

Required Request Value

The request value is a data-structure with various fields. Each field may be a simple scalar or another data-structure. In the latter case it is advised to set the field-cursor to the data-structure's field to specify values more concisely.

For example, a structure like this:

GoogleCloudRetailV2UserEvent:
  attribution-token: string
  cart-id: string
  completion-detail:
    completion-attribution-token: string
    selected-position: integer
    selected-suggestion: string
  entity: string
  event-time: string
  event-type: string
  experiment-ids: [string]
  filter: string
  offset: integer
  order-by: string
  page-categories: [string]
  page-view-id: string
  purchase-transaction:
    cost: number
    currency-code: string
    id: string
    revenue: number
    tax: number
  referrer-uri: string
  search-query: string
  session-id: string
  uri: string
  user-info:
    direct-user-request: boolean
    ip-address: string
    user-agent: string
    user-id: string
  visitor-id: string

can be set completely with the following arguments which are assumed to be executed in the given order. Note how the cursor position is adjusted to the respective structures, allowing simple field names to be used most of the time.

  • -r . attribution-token=clita
    • Highly recommended for user events that are the result of PredictionService.Predict. This field enables accurate attribution of recommendation model performance. The value must be a valid PredictResponse.attribution_token for user events that are the result of PredictionService.Predict. The value must be a valid SearchResponse.attribution_token for user events that are the result of SearchService.Search. This token enables us to accurately attribute page view or purchase back to the event and the particular predict response containing this clicked/purchased product. If user clicks on product K in the recommendation results, pass PredictResponse.attribution_token as a URL parameter to product K's page. When recording events on product K's page, log the PredictResponse.attribution_token to this field.
  • cart-id=sed
    • The ID or name of the associated shopping cart. This ID is used to associate multiple items added or present in the cart before purchase. This can only be set for add-to-cart, purchase-complete, or shopping-cart-page-view events.
  • completion-detail completion-attribution-token=no
    • Completion attribution token in CompleteQueryResponse.attribution_token.
  • selected-position=36
    • End user selected CompleteQueryResponse.CompletionResult.suggestion position, starting from 0.
  • selected-suggestion=sea

    • End user selected CompleteQueryResponse.CompletionResult.suggestion.
  • .. entity=clita

    • The entity for customers that may run multiple different entities, domains, sites or regions, for example, Google US, Google Ads, Waymo, google.com, youtube.com, etc. We recommend that you set this field to get better per-entity search, completion, and prediction results.
  • event-time=consetetur
    • Only required for UserEventService.ImportUserEvents method. Timestamp of when the user event happened.
  • event-type=dolores
    • Required. User event type. Allowed values are: * add-to-cart: Products being added to cart. * category-page-view: Special pages such as sale or promotion pages viewed. * detail-page-view: Products detail page viewed. * home-page-view: Homepage viewed. * promotion-offered: Promotion is offered to a user. * promotion-not-offered: Promotion is not offered to a user. * purchase-complete: User finishing a purchase. * search: Product search. * shopping-cart-page-view: User viewing a shopping cart.
  • experiment-ids=sit
    • A list of identifiers for the independent experiment groups this user event belongs to. This is used to distinguish between user events associated with different experiment setups (e.g. using Retail API, using different recommendation models).
    • Each invocation of this argument appends the given value to the array.
  • filter=sea
    • The filter syntax consists of an expression language for constructing a predicate from one or more fields of the products being filtered. See SearchRequest.filter for definition and syntax. The value must be a UTF-8 encoded string with a length limit of 1,000 characters. Otherwise, an INVALID_ARGUMENT error is returned.
  • offset=43
    • An integer that specifies the current offset for pagination (the 0-indexed starting location, amongst the products deemed by the API as relevant). See SearchRequest.offset for definition. If this field is negative, an INVALID_ARGUMENT is returned. This can only be set for search events. Other event types should not set this field. Otherwise, an INVALID_ARGUMENT error is returned.
  • order-by=kasd
    • The order in which products are returned. See SearchRequest.order_by for definition and syntax. The value must be a UTF-8 encoded string with a length limit of 1,000 characters. Otherwise, an INVALID_ARGUMENT error is returned. This can only be set for search events. Other event types should not set this field. Otherwise, an INVALID_ARGUMENT error is returned.
  • page-categories=eirmod
    • The categories associated with a category page. To represent full path of category, use '>' sign to separate different hierarchies. If '>' is part of the category name, replace it with other character(s). Category pages include special pages such as sales or promotions. For instance, a special sale page may have the category hierarchy: "pageCategories" : ["Sales > 2017 Black Friday Deals"]. Required for category-page-view events. At least one of search_query or page_categories is required for search events. Other event types should not set this field. Otherwise, an INVALID_ARGUMENT error is returned.
    • Each invocation of this argument appends the given value to the array.
  • page-view-id=dolores
    • A unique ID of a web page view. This should be kept the same for all user events triggered from the same pageview. For example, an item detail page view could trigger multiple events as the user is browsing the page. The pageViewId property should be kept the same for all these events so that they can be grouped together properly. When using the client side event reporting with JavaScript pixel and Google Tag Manager, this value is filled in automatically.
  • purchase-transaction cost=0.9001803736464893
    • All the costs associated with the products. These can be manufacturing costs, shipping expenses not borne by the end user, or any other costs, such that: * Profit = revenue - tax - cost
  • currency-code=dolor
    • Required. Currency code. Use three-character ISO-4217 code.
  • id=vero
    • The transaction ID with a length limit of 128 characters.
  • revenue=0.26880640935869715
    • Required. Total non-zero revenue or grand total associated with the transaction. This value include shipping, tax, or other adjustments to total revenue that you want to include as part of your revenue calculations.
  • tax=0.27549071635704625

    • All the taxes associated with the transaction.
  • .. referrer-uri=sea

    • The referrer URL of the current page. When using the client side event reporting with JavaScript pixel and Google Tag Manager, this value is filled in automatically.
  • search-query=sadipscing
    • The user's search query. See SearchRequest.query for definition. The value must be a UTF-8 encoded string with a length limit of 5,000 characters. Otherwise, an INVALID_ARGUMENT error is returned. At least one of search_query or page_categories is required for search events. Other event types should not set this field. Otherwise, an INVALID_ARGUMENT error is returned.
  • session-id=dolore
    • A unique identifier for tracking a visitor session with a length limit of 128 bytes. A session is an aggregation of an end user behavior in a time span. A general guideline to populate the sesion_id: 1. If user has no activity for 30 min, a new session_id should be assigned. 2. The session_id should be unique across users, suggest use uuid or add visitor_id as prefix.
  • uri=amet
    • Complete URL (window.location.href) of the user's current page. When using the client side event reporting with JavaScript pixel and Google Tag Manager, this value is filled in automatically. Maximum length 5,000 characters.
  • user-info direct-user-request=true
    • True if the request is made directly from the end user, in which case the ip_address and user_agent can be populated from the HTTP request. This flag should be set only if the API request is made directly from the end user such as a mobile app (and not if a gateway or a server is processing and pushing the user events). This should not be set when using the JavaScript tag in UserEventService.CollectUserEvent.
  • ip-address=invidunt
    • The end user's IP address. This field is used to extract location information for personalization. This field must be either an IPv4 address (e.g. "104.133.9.80") or an IPv6 address (e.g. "2001:0db8:85a3:0000:0000:8a2e:0370:7334"). Otherwise, an INVALID_ARGUMENT error is returned. This should not be set when: * setting SearchRequest.user_info. * using the JavaScript tag in UserEventService.CollectUserEvent or if direct_user_request is set.
  • user-agent=dolores
    • User agent as included in the HTTP header. Required for getting SearchResponse.sponsored_results. The field must be a UTF-8 encoded string with a length limit of 1,000 characters. Otherwise, an INVALID_ARGUMENT error is returned. This should not be set when using the client side event reporting with GTM or JavaScript tag in UserEventService.CollectUserEvent or if direct_user_request is set.
  • user-id=diam

    • Highly recommended for logged-in users. Unique identifier for logged-in user, such as a user name. Don't set for anonymous users. Always use a hashed value for this ID. Don't set the field to the same fixed ID for different users. This mixes the event history of those users together, which results in degraded model quality. The field must be a UTF-8 encoded string with a length limit of 128 characters. Otherwise, an INVALID_ARGUMENT error is returned.
  • .. visitor-id=sanctus

    • Required. A unique identifier for tracking visitors. For example, this could be implemented with an HTTP cookie, which should be able to uniquely identify a visitor on a single device. This unique identifier should not change if the visitor log in/out of the website. Don't set the field to the same fixed ID for different users. This mixes the event history of those users together, which results in degraded model quality. The field must be a UTF-8 encoded string with a length limit of 128 characters. Otherwise, an INVALID_ARGUMENT error is returned. The field should not contain PII or user-data. We recommend to use Google Analytics Client ID for this field.

About Cursors

The cursor position is key to comfortably set complex nested structures. The following rules apply:

  • The cursor position is always set relative to the current one, unless the field name starts with the . character. Fields can be nested such as in -r f.s.o .
  • The cursor position is set relative to the top-level structure if it starts with ., e.g. -r .s.s
  • You can also set nested fields without setting the cursor explicitly. For example, to set a value relative to the current cursor position, you would specify -r struct.sub_struct=bar.
  • You can move the cursor one level up by using ... Each additional . moves it up one additional level. E.g. ... would go three levels up.

Optional Output Flags

The method's return value a JSON encoded structure, which will be written to standard output by default.

  • -o out
    • out specifies the destination to which to write the server's result to. It will be a JSON-encoded structure. The destination may be - to indicate standard output, or a filepath that is to contain the received bytes. If unset, it defaults to standard output.

Optional Method Properties

You may set the following properties to further configure the call. Please note that -p is followed by one or more key-value-pairs, and is called like this -p k1=v1 k2=v2 even though the listing below repeats the -p for completeness.

  • -p write-async=boolean
    • If set to true, the user event will be written asynchronously after validation, and the API will respond without waiting for the write. Therefore, silent failures can occur even if the API returns success. In case of silent failures, error messages can be found in Stackdriver logs.

Optional General Properties

The following properties can configure any call, and are not specific to this method.

  • -p $-xgafv=string

    • V1 error format.
  • -p access-token=string

    • OAuth access token.
  • -p alt=string

    • Data format for response.
  • -p callback=string

    • JSONP
  • -p fields=string

    • Selector specifying which fields to include in a partial response.
  • -p key=string

    • API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
  • -p oauth-token=string

    • OAuth 2.0 token for the current user.
  • -p pretty-print=boolean

    • Returns response with indentations and line breaks.
  • -p quota-user=string

    • Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
  • -p upload-type=string

    • Legacy upload protocol for media (e.g. "media", "multipart").
  • -p upload-protocol=string

    • Upload protocol for media (e.g. "raw", "multipart").