src/basis/tracker.js
function addDispatcher(dispatcher, events, transformer){
  if (!dispatcher || typeof dispatcher.addHandler != 'function')
  {
    /** @cut */ basis.dev.warn(namespace + '.addDispatcher(): First argument should have `addHandler` method');
    return;
  }

  if (typeof events == 'string')
    events = events.split(/\s+/);

  if (!Array.isArray(events))
  {
    /** @cut */ basis.dev.warn(namespace + '.addDispatcher(): Second argument should be a list of events');
    return;
  }

  if (typeof transformer != 'function')
  {
    /** @cut */ basis.dev.warn(namespace + '.addDispatcher(): Third argument should be a function');
    return;
  }

  dispatcher.addHandler({
    '*': function(event){
      if (events.indexOf(event.type) != -1)
      {
        var eventName = event.type;
        var selectorList = getSelectorList(eventName);

        selectorList.forEach(function(item){
          var data = transformer(event, item);

          if (data)
            track(data);
        });
      }
    }
  });

  return true;
}
function addDispatcher(dispatcher, events, transformer){
  if (!dispatcher || typeof dispatcher.addHandler != 'function')
  {
    /** @cut */ basis.dev.warn(namespace + '.addDispatcher(): First argument should have `addHandler` method');
    return;
  }

  if (typeof events == 'string')
    events = events.split(/\s+/);

  if (!Array.isArray(events))
  {
    /** @cut */ basis.dev.warn(namespace + '.addDispatcher(): Second argument should be a list of events');
    return;
  }

  if (typeof transformer != 'function')
  {
    /** @cut */ basis.dev.warn(namespace + '.addDispatcher(): Third argument should be a function');
    return;
  }

  dispatcher.addHandler({
    '*': function(event){
      if (events.indexOf(event.type) != -1)
      {
        var eventName = event.type;
        var selectorList = getSelectorList(eventName);

        selectorList.forEach(function(item){
          var data = transformer(event, item);

          if (data)
            track(data);
        });
      }
    }
  });

  return true;
}
function addDispatcher ( dispatcher , events , transformer ) { if ( ! dispatcher || typeof dispatcher . addHandler != 'function' ) { /** @cut */ basis . dev . warn ( namespace + '.addDispatcher(): First argument should have `addHandler` method' ) ; return ; } if ( typeof events == 'string' ) events = events . split ( / \s+ / ) ; if ( ! Array . isArray ( events ) ) { /** @cut */ basis . dev . warn ( namespace + '.addDispatcher(): Second argument should be a list of events' ) ; return ; } if ( typeof transformer != 'function' ) { /** @cut */ basis . dev . warn ( namespace + '.addDispatcher(): Third argument should be a function' ) ; return ; } dispatcher . addHandler ( { '*' : function ( event ) { if ( events . indexOf ( event . type ) != - 1 ) { var eventName = event . type ; var selectorList = getSelectorList ( eventName ) ; selectorList . forEach ( function ( item ) { var data = transformer ( event , item ) ; if ( data ) track ( data ) ; } ) ; } } } ) ; return true ; }
A way to add custom data to a tracking data object
@param {{ addHandler: function(object) }} dispatcher basis.net.transportDispatcher or another basis.event.Emitter or any object with addHandler function
@param {string|Array} events list of events recognizable by `dispatcher`
@param {function(event, item):object} transformer function should return a tracking data object
@return {undefined|boolean}
A way to add custom data to a tracking data object