[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[],[],null,["# Implement user events\n\nTo configure your user events:\n\n1. Import [historical user events](/retail/docs/import-user-events).\n\n2. Record [live user events](/retail/docs/record-events).\n\n3. Tag user events [with entities](/retail/docs/entities).\n\n4. Flag user events with [attribution tokens](/retail/docs/record-events#attribution-tokens).\n\nUser information\n----------------\n\nThe `visitorId` value represents the unique user identifier. It's required when you record a user event. ([`UserInfo`](/retail/docs/reference/rest/v2/projects.locations.catalogs.userEvents#userinfo)) is included when you record a user event that has the `visitorId` value and, if available, the `userId` value.\n\nYou can use the optional `userId` value as a unique, persistent identifier for a user across devices whenever a user signs in to your site. When you record the `userId` for a user, Vertex AI Search for commerce can generate more personalized results for one user across multiple devices, such as a mobile device and web browser.\n| **Note:** Use a secure form of a unique identifier to keep users anonymous to Vertex AI Search for commerce and protect your users' privacy. You are responsible for redacting PII (personally identifiable information), such as email or home addresses, from your data.\n\nUser event timestamp\n--------------------\n\nWhen you record a user event, be sure to include an accurate timestamp of when\nthe event occurred. Accurate timestamps ensure that events are stored in the\ncorrect order. Timestamps are recorded automatically for events collected using\nTag Manager and the JavaScript Pixel. When you\nimport events, you must provide the timestamp in the [`eventTime`](/retail/docs/reference/rest/v2/projects.locations.catalogs.userEvents#UserEvent.FIELDS.event_time)\nfield in the format specified by\n[RFC 3339](https://tools.ietf.org/html/rfc3339).\n\nCustom attributes for user events\n---------------------------------\n\nYou can include additional custom attributes and features for user events. This\ncan result in improved, more specific recommendations for your users when you\nuse recommendations. To add custom attributes, use\n[`attributes`](/retail/docs/reference/rest/v2/projects.locations.catalogs.userEvents#UserEvent.FIELDS.attributes) when you record a user event.\n\nIf you provide custom attributes for ingested user events, it's important to\nalso include them in the user events that you associate with prediction\nrequests. The formatting of custom attributes must be consistent between\nimported events and events provided with prediction requests. This enables\nuse of those custom attributes when training models and\nserving predictions, which helps improve recommendation quality.\n\nYou can provide custom text values by using the `text` field, or custom\nnumerical values by using the `number` field.\n\nFor example, the following shows the `attributes` section from a request\nto record a user event: \n\n```json\n\"attributes\": {\n \"user_age\": {\"text\": [\"teen\", \"young adult\"]},\n \"user_location\": {\"text\": [\"CA\"]}\n}\n```\n\nMonitor import health\n---------------------\n\nRecording user events successfully is important for getting high-quality\nresults. You should monitor the event recording error rates and take\naction if needed. For more information, see\n[Setting up alerts for data upload issues](/retail/docs/monitor)."]]