Fetch stats from Chrome webstore page
npm install chrome-webstore-stats



npm install chrome-webstore-stats to install the dependencies and module to your project.
javascript
const chromeStoreStats = require('chrome-webstore-stats');
var data = await chromeStoreStats('gkkmiofalnjagdcjheckamobghglpdpm');
if (data.error) {
console.log(data);
}
console.log(data);
// {
// success: true,
// error: false,
// name: 'YouTube Windowed FullScreen',
// installCount: 12651,
// ratingCount: 158,
// ratingValue: 4.550632911392405
// }
`
Using promises:
`javascript
const chromeStoreStats = require('chrome-webstore-stats');
chromeStoreStats('gkkmiofalnjagdcjheckamobghglpdpm').then(function(data) {
if (data.error) {
console.log(data);
}
console.log(data);
// {
// success: true,
// error: false,
// name: 'YouTube Windowed FullScreen',
// installCount: 12651,
// ratingCount: 158,
// ratingValue: 4.550632911392405
// }
});
`
Array of extension ID's example:
`javascript
const chromeStoreStats = require('chrome-webstore-stats');
var data = await awaitchromeStoreStats(['gkkmiofalnjagdcjheckamobghglpdpm', 'gkkmiofalnjagdcjheckamobghglpdpz', 'cfidkbgamfhdgmedldkagjopnbobdmdn']);
console.log(data);
// {
// gkkmiofalnjagdcjheckamobghglpdpm: {
// success: true,
// error: false,
// name: 'YouTube Windowed FullScreen',
// installCount: 12651,
// ratingCount: 158,
// ratingValue: 4.550632911392405
// },
// gkkmiofalnjagdcjheckamobghglpdpz: {
// success: false,
// error: "Couldn't find extension with ID gkkmiofalnjagdcjheckamobghglpdpz",
// name: '',
// installCount: 0,
// ratingCount: 0,
// ratingValue: 0
// },
// cfidkbgamfhdgmedldkagjopnbobdmdn: {
// success: true,
// error: false,
// name: 'Social Blade',
// installCount: 362735,
// ratingCount: 837,
// ratingValue: 4.117084826762246
// }
// }
`
Data will be returned in the following JSON format. These are returned in JSON format as follows:
`
{
success: true/false,
error: false/"string explaining what went wrong",
name: "Name of the extension/webstore listing"
installCount: "Number of installs",
ratingCount: "Number of votes",
ratingValue: "Average star rating out of 5"
}
`
Above data format will be provided inside an object, where key is the extension ID and value is the JSON when an array of extension ID's is provided to the function.
Approach
All code is hosted in index.js as it's a quite straight forward function.
Provided with an extension ID (32 long alpha string from end of the webstore link), the end point will extract using regex the relevant data fields and return them in JSON format. If any error occurs, error will be populated in the response.
Given an array, the same data will be returned to user however as an Object where the extension ID will be the key, and the value will be the requested data.
To use as an endpoint, have a look at this endpoint example at https://github.com/navi1995/Chrome-Webstore-Stats-API
`javascript
function getChromeStoreDetails() {
$.ajax({
url: '/webstore-stats?id={extensionID}',
method: 'GET',
contentType: 'application/json; charset=utf-8',
dataType: 'json'
}).done(function (data, textStatus, jqXHR) {
if (data.installCount) $("#installCount").html(data.installCount);
if (data.ratingValue) $("#ratingValue").html(Math.round((data.ratingValue + Number.EPSILON) * 100) / 100);
if (data.ratingCount) $("#ratingCount").html(data.ratingCount);
});
}
``