src/google_analytics/ga-feeder.js
/**
   *
   * Fetcher for the most popular articles on /apptweak.com/aso-blog.
   *
   * @param {Object} config - The config require for the fetch
   * @return {Promise} - The promisified geckoFormatted result of the fetch
   *
   */
Fetcher for the most popular articles on /apptweak.com/aso-blog.
@param {Object} config - The config require for the fetch
@return {Promise} - The promisified geckoFormatted result of the fetch
Fetcher for the most popular articles on / apptweak . com / aso - blog . @param { Object } config - The config require for the fetch @return { Promise } - The promisified geckoFormatted result of the fetch
async fetchMostBlogPost(config) {
    const metrics = ['ga:pageviews'];
    const dimensions = ['ga:pagePath', 'ga:pageTitle'];
    const filters = ['ga:pagePathLevel1', '==', '/aso-blog/'];
    let {
      rows: tops,
    } = await this.requestGAFor({
      'start-date': config['start-date'],
      'end-date': config['end-date'],
      'max-results': 4,
      'sort': '-ga:pageviews',
      metrics,
      dimensions,
      filters,
    });
    let oldTopValue = await Promise.all(tops.map(async([path]) => {
      return this.requestGAFor({
        'start-date': config['last-start-date'],
        'end-date': config['last-end-date'],
        'max-results': 1,
        'filters': ['ga:pagePath', '==', path],
        metrics,
        dimensions,
      });
    }));
    oldTopValue = oldTopValue.map(({
        rows,
      }) => (rows) ? rows.pop() : [])
      .reduce((old, [path = '', , nbViews = 0]) => {
        old[path] = nbViews;
        return old;
      }, {});
    tops = tops.map(([path, title, nbViews]) => {
      return [
        title.replace(' - ASO Blog', ''),
        nbViews,
        (oldTopValue[path] || 0),
        path,
      ];
    });
    switch (config.out) {
      default:
        const html = HTMLFormatter.toTextForBlogPostViews(tops);
      return GeckoBoardFormatter.toText(html);
      case 'json':
          return tops.map(([title, nbViews, oldViews, path]) => ({
          title,
          path,
          nbViews,
          oldViews,
        }));
      case 'list':
          return GeckoBoardFormatter.toLeaderboard(
          tops.map(([title, nbViews]) =>
            ({
              'label': title,
              'value': nbViews,
            })
          ));
    }
  }
async fetchMostBlogPost ( config ) { const metrics = [ 'ga:pageviews' ] ; const dimensions = [ 'ga:pagePath' , 'ga:pageTitle' ] ; const filters = [ 'ga:pagePathLevel1' , '==' , '/aso-blog/' ] ; let { rows : tops , } = await this . requestGAFor ( { 'start-date' : config [ 'start-date' ] , 'end-date' : config [ 'end-date' ] , 'max-results' : 4 , 'sort' : '-ga:pageviews' , metrics , dimensions , filters , } ) ; let oldTopValue = await Promise . all ( tops . map ( async ( [ path ] ) => { return this . requestGAFor ( { 'start-date' : config [ 'last-start-date' ] , 'end-date' : config [ 'last-end-date' ] , 'max-results' : 1 , 'filters' : [ 'ga:pagePath' , '==' , path ] , metrics , dimensions , } ) ; } ) ) ; oldTopValue = oldTopValue . map ( ( { rows , } ) => ( rows ) ? rows . pop ( ) : [ ] ) . reduce ( ( old , [ path = '' , , nbViews = 0 ] ) => { old [ path ] = nbViews ; return old ; } , { } ) ; tops = tops . map ( ( [ path , title , nbViews ] ) => { return [ title . replace ( ' - ASO Blog' , '' ) , nbViews , ( oldTopValue [ path ] || 0 ) , path , ] ; } ) ; switch ( config . out ) { default : const html = HTMLFormatter . toTextForBlogPostViews ( tops ) ; return GeckoBoardFormatter . toText ( html ) ; case 'json' : return tops . map ( ( [ title , nbViews , oldViews , path ] ) => ( { title , path , nbViews , oldViews , } ) ) ; case 'list' : return GeckoBoardFormatter . toLeaderboard ( tops . map ( ( [ title , nbViews ] ) => ( { 'label' : title , 'value' : nbViews , } ) ) ) ; } }
Fetcher for the most popular articles on /apptweak.com/aso-blog.
Fetcher for the most popular articles on / apptweak . com / aso - blog .
// CANNOT be stored in cache coz the most post can change in the month. // Insert the old value into tops