Queueing events using the Engage SDK
Using the Engage SDK, you can collect events and send them later in one go. This is useful when, for example, you want to conditionally chain different events depending on which actions your user takes.
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 EngageEventQueue
key. You can add any event with a valid payload to the event queue.
The event queue requires that session storage is enabled. Because users can disable session storage, you should use try-catch blocks to handle errors when you're interacting with the event queue.
To interact with the event queue, you can use the following functions:
-
Engage.addToEventQueue()
- to add event objects with a valid payload to the event queue. -
Engage.processEventQueue()
- to send all the events in the event queue, in the order the events were added. Then, this function empties the event queue. -
Engage.clearEventQueue()
- to empty the event queue without sending any of the events.