This page describes how to view user event information and purge user events.

To record user events as they happen, see
[Record real-time user events](https://docs.cloud.google.com/generative-ai-app-builder/docs/record-user-events.md.txt). To import user event data from
past events, see [Import historical user events](https://docs.cloud.google.com/generative-ai-app-builder/docs/import-user-events.md.txt).

## View aggregated user event information

You can see information about recorded user events for your app in the
Google Cloud console on the **Events** tab of your app's **Data** page.

This page shows information such as number of events ingested, number of
unjoined events, percentage change in number of events over a period, and
average count of event type per document. In addition, you can see metrics for
each event type over time. Metrics appear about 24 hours after you first upload
events.

To see your user event information:

1. In the Google Cloud console, go to the **AI Applications** page.

   [AI Applications](https://console.cloud.google.com/gen-app-builder/start)
2. Click the name of the app that you want to see user event information for.

3. On the **Data** page, go to the **Events** tab. User event information is
   displayed on this tab.

## Purge user events

If you have user events that were not recorded correctly and need to remove
them, you can do so using the [`userEvents.purge`](https://docs.cloud.google.com/generative-ai-app-builder/docs/reference/rest/v1/projects.locations.dataStores.userEvents/purge.md.txt) API method.
Although you [record](https://docs.cloud.google.com/generative-ai-app-builder/docs/record-user-events.md.txt) and
[import](https://docs.cloud.google.com/generative-ai-app-builder/docs/import-user-events.md.txt) at a location level, you must purge
user events at the data-store level.

Specify the events you want to remove by using a [user event filter](https://docs.cloud.google.com/generative-ai-app-builder/docs/manage-user-events.md.txt#filter).
You can use the user event filter to specify the events that you want to purge.
You can filter with the `eventTime`, `eventType`, `visitorID`, and `userID`
fields.

This example filters for a time range, which must use the
[Zulu Time date format](https://www.ietf.org/rfc/rfc3339.txt).

```bash
curl -X POST \
  -H "Authorization: Bearer "$(gcloud auth application-default print-access-token)"" \
  -H "Content-Type: application/json; charset=utf-8" \
  --data '{
    "filter":"eventTime > \"2023-12-21T18:25:43.511Z\" eventTime < \"2023-12-21T18:30:43.511Z\"",
  }' \
  "https://discoveryengine.googleapis.com/v1/projects/PROJECT_NUMBER/locations/global/dataStores/DATA_STORE_ID/userEvents:purge"
```

You should receive a response object similar to the following, where
`purge-user-events-54321` is the operation ID:

```bash
{
  "name": "projects/PROJECT_NUMBER/locations/global/catalogs/default_catalog/operations/purge-user-events-54321"
}
```

This example requests the operation status:

```bash
curl -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_NUMBER/locations/global/dataStores/DATA_STORE_ID/operations/OPERATION_ID"
```

Operation status example:

```bash
{
  "name": "projects/PROJECT_NUMBER/locations/global/catalogs/default_catalog/operations/OPERATION_ID",
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.discoveryengine.v1.PurgeUserEventsResponse"
    "purgedEventsCount": "1"
  }
}
```

<br />

## Use the user event filter

You can filter user events to be deleted.

The filter is a string that contains one or more of the following restrictions:

- `eventTime`: Provides a timestamp to bound the events to be deleted. This
  filter can be specified once or twice, with a greater-than (`>`) or less-than
  (`<`) symbol. The bounded time must be a single contiguous block.

- `eventType`: Restrict the events to be deleted to a single event type.

- `visitorID`: Restrict the events to be deleted to a single visitor ID.

- `userID`: Restrict the events to be deleted to a single user ID.

Only user events that satisfy all of the restrictions are deleted.

For example, to delete all user events of type `add-to-cart` that were logged
on or after February 1, 2023, you would provide the following filter string:

```bash
eventTime > "2023-02-01T00:00:00Z" eventType = add-to-cart
```

## What's next

- [Record real-time user events](https://docs.cloud.google.com/generative-ai-app-builder/docs/record-user-events.md.txt)
- [Import historical user events](https://docs.cloud.google.com/generative-ai-app-builder/docs/import-user-events.md.txt).