diff --git a/client/state/stats/lists/test/actions.js b/client/state/stats/lists/test/actions.js index 5e652b2e41914..271d7d418c007 100644 --- a/client/state/stats/lists/test/actions.js +++ b/client/state/stats/lists/test/actions.js @@ -54,7 +54,7 @@ describe( 'actions', () => { .persist() .get( `/rest/v1.1/sites/${ SITE_ID }/stats/streak?startDate=2015-06-01&endDate=2016-06-01` ) .reply( 200, STREAK_RESPONSE ) - .get( `/rest/v1.1/sites/${ SITE_ID }/stats/country-views` ) + .get( `/rest/v1.1/sites/${ SITE_ID }/stats/location-views/country` ) .reply( 404, { error: 'not_found', } ) diff --git a/client/state/stats/lists/utils.js b/client/state/stats/lists/utils.js index d919bee3e825d..49d9b7686791b 100644 --- a/client/state/stats/lists/utils.js +++ b/client/state/stats/lists/utils.js @@ -397,13 +397,13 @@ export const normalizers = { }, /** - * Returns a normalized payload from `/sites/{ site }/stats/country-views` + * Returns a normalized payload from `/sites/{ site }/stats/location-views/country` * @param {Object} data Stats data * @param {Object} query Stats query * @returns {Object | null} Normalized stats data */ statsCountryViews: ( data, query = {} ) => { - // parsing a country-views response requires a period and date + // parsing a location-views response requires a period and date if ( ! data || ! query.period || ! query.date ) { return null; } @@ -415,6 +415,19 @@ export const normalizers = { // filter out country views that have no legitimate country data associated with them const countryData = filter( get( data, dataPath, [] ), ( viewData ) => { + // Ignore the unknown location of sources from the legacy stats geoviews table. + if ( [ 'A1', 'A2', 'ZZ' ].includes( viewData.country_code ) ) { + return false; + } + + // TODO: Investigate ignored countries that have `false` as the country_full data. + if ( + countryInfo[ viewData.country_code ] && + ! countryInfo[ viewData.country_code ].country_full + ) { + return false; + } + return countryInfo[ viewData.country_code ]; } ); diff --git a/packages/wpcom.js/docs/site.md b/packages/wpcom.js/docs/site.md index 4c2b03ba8a017..9b28d204ca80f 100644 --- a/packages/wpcom.js/docs/site.md +++ b/packages/wpcom.js/docs/site.md @@ -156,11 +156,11 @@ site.statsComments( function ( err, data ) { ### Site#statsCountryViews([query, ]fn) -Returns stats [country views](https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/stats/country-views/) data. +Returns stats [country views](https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/stats/location-views/country/) data. ```js site.statsCountryViews( function ( err, data ) { - // data country-views response + // data location-views response } ); ``` diff --git a/packages/wpcom.js/src/lib/runtime/site.get.js b/packages/wpcom.js/src/lib/runtime/site.get.js index 406ca2e1835f9..5782c3f72e404 100644 --- a/packages/wpcom.js/src/lib/runtime/site.get.js +++ b/packages/wpcom.js/src/lib/runtime/site.get.js @@ -14,7 +14,7 @@ export default [ { name: 'statsClicks', subpath: 'stats/clicks' }, { name: 'statsCommentFollowers', subpath: 'stats/comment-followers' }, { name: 'statsComments', subpath: 'stats/comments' }, - { name: 'statsCountryViews', subpath: 'stats/country-views' }, + { name: 'statsCountryViews', subpath: 'stats/location-views/country' }, { name: 'statsFollowers', subpath: 'stats/followers' }, { name: 'statsInsights', subpath: 'stats/insights' }, { name: 'statsPublicize', subpath: 'stats/publicize' },