---
title: "clearEventQueue"
slug: "cloud-sdk-events-browser-cleareventqueue"
abstract: "The clearEventQueue function empties the event queue, removing all the events in it, without sending any of the events."
---
# clearEventQueue

|     |     |
| --- | --- |
| Type | Function |
| Import path | `@sitecore-cloudsdk/events/browser` |

Empties the event queue, removing all the events that are in it, without sending any of the events.

## Signature

```typescript
export async function clearEventQueue(): Promise<void>
```

## Return value

Returns a promise.

## Examples

:::tab{title="Next.js"}

Example 38. Running the clearEventQueue function

:::tab{title="Next.js"}
> [!note]
> To run this function, you have to first [initialize](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-events/cloud-sdk-events-browser/functions/cloud-sdk-core-browser-cloudsdk.html "CloudSDK") the Cloud SDK.

Here's an example of how to use the `clearEventQueue` function to empty the event queue.

In this scenario, we add different events to the event queue depending on whether a site visitor clicked a dropdown menu and a dropdown menu item.

If a certain condition is met, you decide to empty the event queue and not send any of the events you previously added to it.

```typescript
"use client"; // Used only in Next.js App Router
import { addToEventQueue, clearEventQueue } from "@sitecore-cloudsdk/events/browser";

export default function Component(){
  const sendEvents = async () => {
    if (true) {
      await addToEventQueue({ type: "DROPDOWN_CLICK" });
      console.log("Added DROPDOWN_CLICK event to event queue.");

      if (true) {
        await addToEventQueue({ type: "DROPDOWN_ITEM_CLICK" });
        console.log("Added DROPDOWN_ITEM_CLICK event to event queue.");
      } else {
        await addToEventQueue({ type: "DROPDOWN_ABANDON" });
        console.log("Added DROPDOWN_ABANDON event to event queue.");
      }

      const timeout = true;
      if (timeout) {
        await clearEventQueue();
        console.log("Did not send any of the queued events.");
      }
    }
  };

  return (
    <div>
      <button onClick={sendEvents}>send events</button>
    </div>
  );
};
```

:::

:::