debounceEvent
If you have an event definition tied to a Redux action that fires too frequently, you can use this util to limit the frequency of analytics events (e.g. form input).

Import

1
import debounceEvent from '@redux-beacon/debounce-event';
Copied!

Syntax

1
debounceEvent(msDelay, eventDef)
Copied!

Parameters

  • msDelay: number
    • The time in milliseconds that needs to elapse between event definition calls
      before the analytics event is dispatched to a target.
  • eventDef: EventDefinition
    • The event you want to debounce.

Example

1
import debounceEvent from '@redux-beacon/debounce-event';
2
3
// A normal event definition
4
const searchTerm = (action) => ({
5
hitType: 'event',
6
eventCategory: 'books',
7
eventAction: 'search',
8
eventLabel: action.payload
9
});
10
11
const eventsMap = {
12
// Assume that SEARCH_TERM_ENTERED fires whenever a user types a character into
13
// an input field.
14
SEARCH_TERM_ENTERED: debounceEvent(1000, searchTerm)
15
// The analytics event will only fire after 1s since the last entered character
16
};
17
18
// provide the events map when creating your middleware or meta reducer...
Copied!
Last modified 3yr ago