Delay the mPulse beacon from firing for X seconds

Document created by DPM Admin Employee on Jul 14, 2017Last modified by Will Smithee on Mar 6, 2018
Version 7Show Document
  • View in full screen mode

In certain cases, you may want to delay the mPulse beacon from firing on the load event.  The code below will delay the firing of the beacon for 2.5 seconds (i.e. the 2500 seen in the code below).  This code is simply prepended inside the main beacon code function that you copy out of the mPulse UI.

 

Note: This code will effectively delay real-time measurement reporting by 2.5 seconds which may also have the side-effect of losing beacon data for any page requests where the user navigates away from the page or closes the browser/application during the delay period.  Making this delay as short as possible is therefore the best practice.

<script>
(function() {
  // Ensure we have the BOOMR namespace to work with
  BOOMR = window.BOOMR || {};
  BOOMR.plugins = BOOMR.plugins || {};

  // holds the beacon until this is true
  var complete = false;

  // create a custom plugin to hold the beacon until we're ready
  BOOMR.plugins.MyCustomPlugin = {
    is_complete: function() {
      return complete;
    }
  };

  function delayBeacon() {
    setTimeout(function() {
      complete = true;

      //trigger the beacon
      if (typeof BOOMR.sendBeacon === "function") {
        BOOMR.sendBeacon();
      }
    }, 2500);
  }

  if (window.addEventListener) {
    window.addEventListener("load", delayBeacon, false);
  } else if (window.attachEvent) {
    window.attachEvent("onload", delayBeacon);
  }

  //#########################################################
  // standard Boomerang loader script function code goes here
  //#########################################################

})();
</script>

Attachments

    Outcomes