src/google_analytics/ga-feeder.js
/**
   *
   * Fetcher for the AVG Session Duration on /apptweak.com.
   *
   * @param {Object} config - The config require for the fetch
   * @return {Promise} - The promisified geckoFormatted result of the fetch
   *
   */
Fetcher for the AVG Session Duration on /apptweak.com.
@param {Object} config - The config require for the fetch
@return {Promise} - The promisified geckoFormatted result of the fetch
Fetcher for the AVG Session Duration on / apptweak . com . @param { Object } config - The config require for the fetch @return { Promise } - The promisified geckoFormatted result of the fetch
async fetchSessionDuration(config) {
    const metrics = ['ga:avgSessionDuration'];
    const query = {
      'current': {
        'start-date': config['start-date'],
        'end-date': config['end-date'],
        metrics,
      },
      'last': {
        'start-date': config['last-start-date'],
        'end-date': config['last-end-date'],
        metrics,
      },
    };
    const [{
      totals: current,
    }, {
      totals: last,
    }] = await Promise.all([
      this.requestGAFor(query.current),
      this.requestGAFor(query.last),
    ]);
    const firstRes = Number.parseFloat(current[metrics[0]]);
    const secondRes = Number.parseFloat(last[metrics[0]]);
    switch (config.out) {
      case 'html':
        const diff = firstRes - secondRes;
        const html = HTMLFormatter.toTextForDuration(firstRes, diff);
        return GeckoBoardFormatter.toText(html);
      default:
        return GeckoBoardFormatter.toNumberAndSecondStat({
          'absolute': true,
          'type': 'time_duration',
          'value': Number.parseFloat(firstRes) * 1000,
        }, {
          'type': 'time_duration',
          'value': Number.parseFloat(secondRes) * 1000,
        });
    }
  }
async fetchSessionDuration ( config ) { const metrics = [ 'ga:avgSessionDuration' ] ; const query = { 'current' : { 'start-date' : config [ 'start-date' ] , 'end-date' : config [ 'end-date' ] , metrics , } , 'last' : { 'start-date' : config [ 'last-start-date' ] , 'end-date' : config [ 'last-end-date' ] , metrics , } , } ; const [ { totals : current , } , { totals : last , } ] = await Promise . all ( [ this . requestGAFor ( query . current ) , this . requestGAFor ( query . last ) , ] ) ; const firstRes = Number . parseFloat ( current [ metrics [ 0 ] ] ) ; const secondRes = Number . parseFloat ( last [ metrics [ 0 ] ] ) ; switch ( config . out ) { case 'html' : const diff = firstRes - secondRes ; const html = HTMLFormatter . toTextForDuration ( firstRes , diff ) ; return GeckoBoardFormatter . toText ( html ) ; default : return GeckoBoardFormatter . toNumberAndSecondStat ( { 'absolute' : true , 'type' : 'time_duration' , 'value' : Number . parseFloat ( firstRes ) * 1000 , } , { 'type' : 'time_duration' , 'value' : Number . parseFloat ( secondRes ) * 1000 , } ) ; } }
Fetcher for the AVG Session Duration on /apptweak.com.
Fetcher for the AVG Session Duration on / apptweak . com .