packages/optimizely-sdk/lib/plugins/event_dispatcher/index.browser.js
function(eventObj, callback) {
    var url = eventObj.url;
    var params = eventObj.params;
    if (eventObj.httpVerb === POST_METHOD) {
      var req = new XMLHttpRequest();
      req.open(POST_METHOD, url, true);
      req.setRequestHeader('Content-Type', 'application/json');
      req.onreadystatechange = function() {
        if (req.readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function') {
          try {
            callback(params);
          } catch (e) {
            // TODO: Log this somehow (consider adding a logger to the EventDispatcher interface)
          }
        }
      };
      req.send(JSON.stringify(params));
    } else {
      // add param for cors headers to be sent by the log endpoint
      url += '?wxhr=true';
      if (params) {
        url += '&' + toQueryString(params);
      }

      var req = new XMLHttpRequest();
      req.open(GET_METHOD, url, true);
      req.onreadystatechange = function() {
        if (req.readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function') {
          try {
            callback();
          } catch (e) {
            // TODO: Log this somehow (consider adding a logger to the EventDispatcher interface)
          }
        }
      };
      req.send();
    }
  }
function(eventObj, callback) {
    var url = eventObj.url;
    var params = eventObj.params;
    if (eventObj.httpVerb === POST_METHOD) {
      var req = new XMLHttpRequest();
      req.open(POST_METHOD, url, true);
      req.setRequestHeader('Content-Type', 'application/json');
      req.onreadystatechange = function() {
        if (req.readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function') {
          try {
            callback(params);
          } catch (e) {
            // TODO: Log this somehow (consider adding a logger to the EventDispatcher interface)
          }
        }
      };
      req.send(JSON.stringify(params));
    } else {
      // add param for cors headers to be sent by the log endpoint
      url += '?wxhr=true';
      if (params) {
        url += '&' + toQueryString(params);
      }

      var req = new XMLHttpRequest();
      req.open(GET_METHOD, url, true);
      req.onreadystatechange = function() {
        if (req.readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function') {
          try {
            callback();
          } catch (e) {
            // TODO: Log this somehow (consider adding a logger to the EventDispatcher interface)
          }
        }
      };
      req.send();
    }
  }
function ( eventObj , callback ) { var url = eventObj . url ; var params = eventObj . params ; if ( eventObj . httpVerb === POST_METHOD ) { var req = new XMLHttpRequest ( ) ; req . open ( POST_METHOD , url , true ) ; req . setRequestHeader ( 'Content-Type' , 'application/json' ) ; req . onreadystatechange = function ( ) { if ( req . readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function' ) { try { callback ( params ) ; } catch ( e ) { // TODO: Log this somehow (consider adding a logger to the EventDispatcher interface) } } } ; req . send ( JSON . stringify ( params ) ) ; } else { // add param for cors headers to be sent by the log endpoint url += '?wxhr=true' ; if ( params ) { url += '&' + toQueryString ( params ) ; } var req = new XMLHttpRequest ( ) ; req . open ( GET_METHOD , url , true ) ; req . onreadystatechange = function ( ) { if ( req . readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function' ) { try { callback ( ) ; } catch ( e ) { // TODO: Log this somehow (consider adding a logger to the EventDispatcher interface) } } } ; req . send ( ) ; } }
Sample event dispatcher implementation for tracking impression and conversions
Users of the SDK can provide their own implementation
@param  {Object} eventObj
@param  {Function} callback
Sample event dispatcher implementation for tracking impression and conversions Users of the SDK can provide their own implementation