javascripts/pushr/dispatchers/index.js

  1. /**
  2. * @namespace javascripts.pushr.dispatchers.index
  3. * @description All push and turbo dispatchers are added here
  4. */
  5. import { pushrDispatcher, leavePageDispatcher } from "~/javascripts/pushr/dispatchers/rum"
  6. export const pushrDispatchers = (pushrObject) => pushrDispatcher(pushrObject)
  7. export const eventListenerDispatchers = () => {
  8. /**
  9. * Dispatch all available metrics whenever the page is backgrounded or unloaded.
  10. */
  11. window.addEventListener("visibilitychange", () => {
  12. if (document.visibilityState === "hidden") leavePageDispatcher()
  13. })
  14. /**
  15. * Safari does not reliably fire the `visibilitychange` event when the page is being unloaded.
  16. * Therefore also dispatch any metrics in the dispatcher on the `pagehide` event
  17. **/
  18. window.addEventListener("pagehide", () => leavePageDispatcher())
  19. }