1. Events

The event queue

Version:

When using client-side tracking, instead of sending events one by one, you can first collect events into a queue, then send them later in one go. This is useful when, for example, you want to conditionally chain different events depending on which actions your site visitor performs.

To collect events, you can use the event queue. The event queue is a first-in, first-out array stored in session storage in the EventQueue key. You can add any event that supports the event queue and has a valid payload.

Important

The event queue requires that session storage is enabled. Because site visitors can disable session storage, you should use try-catch blocks when you're setting up the event queue.

To interact with the event queue, you can use the following asynchronous functions:

  • addToEventQueue - adds an event object with a valid payload to the event queue.

  • processEventQueue - sends all the events in the event queue, in the order they were added. Afterwards, this function empties the event queue.

  • clearEventQueue - empties the event queue without sending any of the events.

If you have suggestions for improving this article, let us know!