src/tracker.js
/**
   * Send an event to tracking servr
   */
Send an event to tracking servr
Send an event to tracking servr
track(name, options) {
    let eventData = {};
    let eventName = '';
    let hash;
    let callback;
    let beforeCallback;
    let errorCallback;
    let lastArg = arguments[arguments.length - 1];
    let lifecycle = LIFECYCLE_ACTION;
    let queue = false;
    let useBeacon = false;
    let timeout;
    let retrack;
    if (isFunction(lastArg)) callback = lastArg;
    else if (isObject(lastArg)) {
      if (isFunction(lastArg.callback)) callback = lastArg.callback;
      else if (isFunction(lastArg.onSuccess)) callback = lastArg.onSuccess;
      if (isFunction(lastArg.onBeforeSend))
        beforeCallback = lastArg.onBeforeSend;
      if (isFunction(lastArg.onError)) errorCallback = lastArg.onError;
      if (!isUndefined(lastArg.lifecycle)) lifecycle = lastArg.lifecycle;
      if (!isUndefined(lastArg.timeout)) timeout = lastArg.timeout;
      if (!isUndefined(lastArg.retrack)) retrack = lastArg.retrack;
      if (this.config(KEY_BEACONS)) {
        if (!isUndefined(lastArg.queue)) queue = Boolean(lastArg.queue);
        if (!isUndefined(lastArg.useBeacon)) {
          useBeacon = Boolean(lastArg.useBeacon);
        } else if (queue) useBeacon = true;
      } else {
        useBeacon = false;
      }
    }
    if (!this.config(KEY_CAMPAIGN_ONCE) || !this.sentCampaign) {
      eventData = { ...eventData, ...Woopra.getCampaignData() };
      this.sentCampaign = true;
    }
    eventData = {
      ...eventData,
      ...Woopra.mapQueryParams(this.config(KEY_MAP_QUERY_PARAMS))
    };
    if (isUndefined(name) || name === callback) {
      eventName = ACTION_PV;
    }
    else if (isUndefined(options) || options === callback) {
      if (isString(name)) {
        eventName = name;
      }
      if (isObject(name)) {
        if (name.name && name.name === ACTION_PV) {
          eventName = ACTION_PV;
        }
        this._dataSetter(eventData, name);
      }
    }
     in format of name,object
    else {
      this._dataSetter(eventData, options);
      eventName = name;
    }
    eventData[IDPTNC] = randomString();
    if (eventName === ACTION_PV) {
      eventData.url = eventData.url || this.getPageUrl();
      eventData.title = eventData.title || this.getPageTitle();
      eventData.domain = eventData.domain || this.getDomainName();
      eventData.uri = eventData.uri || this.getURI();
      eventData[SCROLL_DEPTH] = getScrollDepth();
      eventData.returning = isUndefined(eventData.returning)
        ? false
        : eventData.returning;
      if (!lastArg || !lastArg.lifecycle) lifecycle = LIFECYCLE_PAGE;
      if (this.config(KEY_SAVE_URL_HASH)) {
        hash = eventData.hash || this.getPageHash();
        if (hash !== '' && hash !== '#') {
          eventData.hash = hash;
        }
      }
    }
    this._push({
      endpoint: ENDPOINT_TRACK,
      visitorData: this.visitorData,
      sessionData: this.sessionData,
      eventName,
      eventData,
      lifecycle,
      callback,
      beforeCallback,
      errorCallback,
      queue,
      useBeacon,
      retrack,
      timeout
    });
    this.startPing();
    return this;
  }
track ( name , options ) { let eventData = { } ; let eventName = '' ; let hash ; let callback ; let beforeCallback ; let errorCallback ; let lastArg = arguments [ arguments . length - 1 ] ; let lifecycle = LIFECYCLE_ACTION ; let queue = false ; let useBeacon = false ; let timeout ; let retrack ; if ( isFunction ( lastArg ) ) callback = lastArg ; else if ( isObject ( lastArg ) ) { if ( isFunction ( lastArg . callback ) ) callback = lastArg . callback ; else if ( isFunction ( lastArg . onSuccess ) ) callback = lastArg . onSuccess ; if ( isFunction ( lastArg . onBeforeSend ) ) beforeCallback = lastArg . onBeforeSend ; if ( isFunction ( lastArg . onError ) ) errorCallback = lastArg . onError ; if ( ! isUndefined ( lastArg . lifecycle ) ) lifecycle = lastArg . lifecycle ; if ( ! isUndefined ( lastArg . timeout ) ) timeout = lastArg . timeout ; if ( ! isUndefined ( lastArg . retrack ) ) retrack = lastArg . retrack ; if ( this . config ( KEY_BEACONS ) ) { if ( ! isUndefined ( lastArg . queue ) ) queue = Boolean ( lastArg . queue ) ; if ( ! isUndefined ( lastArg . useBeacon ) ) { useBeacon = Boolean ( lastArg . useBeacon ) ; } else if ( queue ) useBeacon = true ; } else { useBeacon = false ; } } if ( ! this . config ( KEY_CAMPAIGN_ONCE ) || ! this . sentCampaign ) { eventData = { ... eventData , ... Woopra . getCampaignData ( ) } ; this . sentCampaign = true ; } eventData = { ... eventData , ... Woopra . mapQueryParams ( this . config ( KEY_MAP_QUERY_PARAMS ) ) } ; if ( isUndefined ( name ) || name === callback ) { eventName = ACTION_PV ; } else if ( isUndefined ( options ) || options === callback ) { if ( isString ( name ) ) { eventName = name ; } if ( isObject ( name ) ) { if ( name . name && name . name === ACTION_PV ) { eventName = ACTION_PV ; } this . _dataSetter ( eventData , name ) ; } } else { this . _dataSetter ( eventData , options ) ; eventName = name ; } eventData [ IDPTNC ] = randomString ( ) ; if ( eventName === ACTION_PV ) { eventData . url = eventData . url || this . getPageUrl ( ) ; eventData . title = eventData . title || this . getPageTitle ( ) ; eventData . domain = eventData . domain || this . getDomainName ( ) ; eventData . uri = eventData . uri || this . getURI ( ) ; eventData [ SCROLL_DEPTH ] = getScrollDepth ( ) ; eventData . returning = isUndefined ( eventData . returning ) ? false : eventData . returning ; if ( ! lastArg || ! lastArg . lifecycle ) lifecycle = LIFECYCLE_PAGE ; if ( this . config ( KEY_SAVE_URL_HASH ) ) { hash = eventData . hash || this . getPageHash ( ) ; if ( hash !== '' && hash !== '#' ) { eventData . hash = hash ; } } } this . _push ( { endpoint : ENDPOINT_TRACK , visitorData : this . visitorData , sessionData : this . sessionData , eventName , eventData , lifecycle , callback , beforeCallback , errorCallback , queue , useBeacon , retrack , timeout } ) ; this . startPing ( ) ; return this ; }
Send an event to tracking servr
Send an event to tracking servr
// Load campaign params (load first to allow overrides) // Load query params mapping into Woopra event // Track default: pageview // Track custom events // Track custom events in format of name,object // Add some defaults for pageview