Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


In order to confirm that the event was sent successfully, open the browser Network tab and confirm that the request to the CardioLog Analytics SaaS events service (/cardiolog/api/client/events) returned the 200 status code.

 

Note: It is highly recommended to use the following code (or similar) to ensure that all the calls to the CardioLog API sendEvent function are executed and no events are lost (in case the CardioLog API object is not yet loaded on the page).

Info
iconfalse
(function (CardioLogAgent) {
  if (CardioLogAgent.API) {
    return;
  }

  var WAIT_FOR_SEC = 10;
  var WAIT_CHECK_INTERVAL_MSEC = 500;

  function createSendEventProxy() {
    var proxy = {
      calls: [],

      fn: function (data, callback) {
        proxy.calls.push({ data: data, callback: callback });
      }
    };

    return proxy;
  }

  var sendEventProxy = createSendEventProxy();
  var totalAttemptsCount = Math.ceil(WAIT_FOR_SEC * 1000 / WAIT_CHECK_INTERVAL_MSEC);

  function waitForSendEventInit(attemptNumber) {
    if (attemptNumber >= totalAttemptsCount) {
      return;
    }

    window.setTimeout(function () {
      if (CardioLogAgent.API.sendEvent === sendEventProxy.fn) {
        waitForSendEventInit(attemptNumber + 1);
      } else {
        var call;
        while ((call = sendEventProxy.calls.shift())) {
          CardioLogAgent.API.sendEvent(call.data, call.callback);
        }
      }
    }, WAIT_CHECK_INTERVAL_MSEC);
  }

  CardioLogAgent.API = { sendEvent: sendEventProxy.fn };
  waitForSendEventInit(0);
})(window.CardioLogAgent || (window.CardioLogAgent = {}));