---
title: "processEventQueue"
slug: "cloud-sdk-events-browser-processeventqueue"
abstract: "The processEventQueue function runs the event queue, sending all the events that are in it."
---
# processEventQueue

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

This function:

- Runs the event queue, sending all the events that are in it.
- Sends the events in the order they were added to the event queue.
- Waits for a response from each event before it sends the next event.
- Empties the event queue.

## Signature

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

## Return value

Returns a promise.

## Examples

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

Example 37. Running the processEventQueue 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 `processEventQueue` function to run 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.

When you run the event queue, either the `DROPDOWN_CLICK` then the `DROPDOWN_ITEM_CLICK` events are sent, or the `DROPDOWN_CLICK` then the `DROPDOWN_ABANDON` events.

```typescript
"use client"; // Used only in Next.js App Router
import { addToEventQueue, processEventQueue } 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.");
      }

      await processEventQueue();
      console.log("Sent all queued events.");
    }
  };

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

:::

:::