[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Manage user events\n\nThis page describes how to view and delete user events. For information about\nrecording user events as they happen, see\n[Record real-time user events](/retail/docs/record-events). To import user event data from\npast events, see [Import historical user events](/retail/docs/import-user-events).\n\nRejoin user events tutorial\n---------------------------\n\nThis tutorial show how to rejoin user events by making a `POST` request to the\n[`userEvents:rejoin`](/retail/docs/reference/rest/v2/projects.locations.catalogs.userEvents/rejoin) endpoint.\n\n*** ** * ** ***\n\nTo follow step-by-step guidance for this task directly in the\nCloud Shell Editor, click **Guide me**:\n\n[Guide me](https://shell.cloud.google.com/?walkthrough_tutorial_id=retail--retail_api_v2_rejoin_user_events_select_language&show=ide&environment_deployment=ide)\n\n*** ** * ** ***\n\nRemove user events tutorial\n---------------------------\n\nThis tutorial show how to purge user events.\n\n*** ** * ** ***\n\nTo follow step-by-step guidance for this task directly in the\nCloud Shell Editor, click **Guide me**:\n\n[Guide me](https://shell.cloud.google.com/?walkthrough_tutorial_id=retail--retail_api_v2_purge_user_events_select_language&show=ide&environment_deployment=ide)\n\n*** ** * ** ***\n\nView aggregated user event information\n--------------------------------------\n\n\nView event integration metrics in the **Events** tab on the Search for commerce console\n**Data** page. This page shows all events written or imported in last year. Metrics can take up\nto 24 hours to appear after successful data ingestion.\n\n\n[Go to the Data page](https://console.cloud.google.com/ai/retail/catalogs/default_catalog/data/)\n\nRejoin user events\n------------------\n\nYou can rejoin user events by making a `POST` request to the\n[`userEvents:rejoin`](/retail/docs/reference/rest/v2/projects.locations.catalogs.userEvents/rejoin) endpoint.\n\nThe rejoin operation joins specified events with the latest version of the\nproduct catalog.\n\nA user event is considered unjoined if the product it is associated with isn't\npresent in the catalog at the time that the user event is ingested. Unjoined\nevents lack detailed product information and are not as useful to training\nmodels and serving results.\n\nIn addition to addressing unjoined events, the rejoin operation can be used to\ncorrect events that have been joined with the wrong product catalog.\n\nYou must have the **Retail AI Admin** IAM role to call this method. A rejoin\noperation can take hours or days to complete. \n\n### curl\n\nSet `userEventRejoinScope` according to the types of events you're rejoining:\n\n- `USER_EVENT_REJOIN_SCOPE_UNSPECIFIED`: Default. Trigger rejoin for both joined and unjoined events.\n- `JOINED_EVENTS`: Trigger rejoin for only joined events.\n- `UNJOINED_EVENTS`: Trigger rejoin for only unjoined events.\n\nThe following example triggers a rejoin for only unjoined events: \n\n```bash\ncurl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth application-default print-access-token)\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n --data \"{\n 'userEventRejoinScope': 'UNJOINED_EVENTS'\n }\" \\\n \"https://retail.googleapis.com/v2/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/catalogs/default_catalog/userEvents:rejoin\"\n```\n\nYou should receive a response object that looks something like this: \n\n```bash\n{\n \"name\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/catalogs/default_catalog/operations/\u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e\"\n}\n```\n\nYou can check the status of the rejoin. Replace \u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e with the\nID of the operation ID returned by the rejoin method: \n\n```bash\ncurl -H \"Authorization: Bearer $(gcloud auth application-default print-access-token)\" \\\n\"https://retail.googleapis.com/v2/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/catalogs/default_catalog/operations/\u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e\"\n```\n\nWhen the operation completes, the operation status returns as `done`: \n\n```bash\n{\n \"name\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/catalogs/default_catalog/operations/\u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e\",\n \"done\": true,\n \"response\": {\n \"@type\": \"type.googleapis.com/google.cloud.retail.v2.RejoinUserEventsResponse\",\n \"rejoinedUserEventsCount\": \"1\"\n }\n}\n```\n\n### Java\n\n public static String rejoinUserEvents(UserEventRejoinScope scope)\n throws IOException, InterruptedException, ExecutionException {\n UserEventServiceClient userEventsClient = getUserEventServiceClient();\n\n RejoinUserEventsRequest request = RejoinUserEventsRequest.newBuilder()\n .setParent(DEFAULT_CATALOG_NAME)\n .setUserEventRejoinScope(scope)\n .build();\n\n String operationName = userEventsClient\n .rejoinUserEventsAsync(request).getName();\n\n userEventsClient.shutdownNow();\n userEventsClient.awaitTermination(2, TimeUnit.SECONDS);\n\n return operationName;\n }\n\n\u003cbr /\u003e\n\nRemove user events\n------------------\n\nGenerally, you should leave user events in place after they have been recorded.\nPurging events is not recommended.\n\nAn event purge can take up to several days to complete. If you plan to reset\nuser events entirely, consider creating a new project instead.\n\nIf you have user events that were not recorded properly and need to remove them,\nyou can do so using the [`userEvents.purge`](/retail/docs/reference/rest/v2/projects.locations.catalogs.userEvents/purge) method.\n\nSpecify the events you want to remove by using a [filter string](#filter). This\nsupports selectively deleting user events by filtering on the `eventTime`,\n`eventType`, `visitorID`, and `userID` fields.\n\nBecause you cannot undo the delete, test your filter string by conducting a dry\nrun before deleting user events. The `force` field is set to `false` by\ndefault; this setting will return the number of events to be deleted without\nactually deleting them. When you are ready to actually delete the user events,\nset the `force` field to `true`. \n\n### curl\n\nThis example filters for a time range, which must use the\n[Zulu Time date format](https://www.ietf.org/rfc/rfc3339.txt).\nThe `force` field is set to `false`. \n\n```bash\ncurl -X POST \\\n -H \"Authorization: Bearer \"$(gcloud auth application-default print-access-token)\"\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n --data '{\n \"filter\":\"eventTime \u003e \\\"2019-12-23T18:25:43.511Z\\\" eventTime \u003c \\\"2019-12-23T18:30:43.511Z\\\"\",\n \"force\":\"false\"\n }' \\\n \"https://retail.googleapis.com/v2/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/catalogs/default_catalog/userEvents:purge\"\n```\n\nYou should receive a response object that looks something like this, where\n`purge-user-events-54321` is the operation ID: \n\n```bash\n{\n \"name\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/catalogs/default_catalog/operations/purge-user-events-54321\"\n}\n```\n\nThis example requests the operation status: \n\n```bash\ncurl -H \"Authorization: Bearer $(gcloud auth application-default print-access-token)\" \\\n\"https://retail.googleapis.com/v2/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/catalogs/default_catalog/operations/\u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e\"\n```\n\nOperation status example: \n\n```bash\n{\n \"name\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/catalogs/default_catalog/operations/\u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e\",\n \"done\": true,\n \"response\": {\n \"@type\": \"type.googleapis.com/google.cloud.retail.v2.PurgeUserEventsResponse\",\n \"purgedEventsCount\": \"1\"\n }\n}\n```\n\n\u003cbr /\u003e\n\nSetting the `force` field to `true` forces the delete to occur. \n\n```bash\ncurl -X POST \\\n -H \"Authorization: Bearer \"$(gcloud auth application-default print-access-token)\"\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n --data '{\n \"filter\":\"eventTime \u003e \\\"2019-12-23T18:25:43.511Z\\\" eventTime \u003c \\\"2019-12-23T18:30:43.511Z\\\"\",\n \"force\":\"true\"\n }' \\\n\"https://retail.googleapis.com/v2/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/catalogs/default_catalog/userEvents:purge\"\n```\n\n### Java\n\n public static String purgeUserEvents(\n String filter)\n throws IOException, InterruptedException, ExecutionException {\n UserEventServiceClient userEventsClient = getUserEventServiceClient();\n\n PurgeUserEventsRequest request = PurgeUserEventsRequest.newBuilder()\n .setParent(DEFAULT_CATALOG_NAME)\n .setFilter(filter)\n .setForce(true)\n .build();\n\n String operationName = userEventsClient\n .purgeUserEventsAsync(request).getName();\n\n userEventsClient.shutdownNow();\n userEventsClient.awaitTermination(2, TimeUnit.SECONDS);\n\n return operationName;\n }\n\n\u003cbr /\u003e\n\nUse the user event filter\n-------------------------\n\nYou can filter user events to be deleted.\n\nThe filter is a string that contains one or more of the following restrictions:\n\n- ***eventTime***\n\n Provides a timestamp to bound the events to be deleted. This filter can\n be specified once or twice, with a greater-than (\\\u003e) or less-than (\\\u003c) symbol.\n The bounded time must be a single, contiguous block.\n- ***eventType***\n\n Restrict the events to be deleted to a single event type.\n- ***visitorID***\n\n Restrict the events to be deleted to a single visitor ID.\n- ***userID***\n\n Restrict the events to be deleted to a single user ID.\n\nOnly user events that satisfy all of the restrictions are deleted.\n\nTo delete all user events of type `add-to-cart` that were logged\non or after February 1, 2019, you would provide the following filter string: \n\n```bash\neventTime \u003e \"2019-02-01T00:00:00Z\" eventType = add-to-cart\n```"]]