npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reviews-collector-android

v0.1.4

Published

Collect reviews for Android apps from the Google Play Store

Downloads

6

Readme

reviews-collector-android

Build Status Code Climate Test Coverage


Getting Started

const Collector = require('reviews-collector-android');
// Create an instance of Collector to get reviews of Instagram and Facebook and only parse 2 pages max
const collector = new Collector(
	['com.instagram.android', 'com.facebook.katana'], 
	{ maxPages: 2 }
);

// Do something when we parse a review
collector.on('review', (result) => {
	console.log(`Found a ${result.review.rating} star review`);
});

// Do something when we finish parsing a page of reviews
collector.on('page complete', (result) => {
	console.log(`Finished page ${result.pageNum} of ${result.appId} and found ${result.reviews.length} reviews`);
});

// Do something when we are done parsing an app
collector.on('done collecting', (result) => {
	if (result.error) {
		console.error('Stopped collecting because something went wrong');
	} else {
		console.log(`Finished collecting reviews for ${result.appId}`);
	}
});

// Exit once we are done with all of the apps
collector.on('done with apps', () => {
    console.log('Finished collecting reviews for all of the apps');
    process.exit();
});

// Start collecting reviews
collector.collect();

Instantiating

First, create a Collector prototype by requiring reviews-collector-android

var Collector = require('reviews-collector-android');

Next, create an Collector instance using the new keyword and passing an app ID and an options object

// The app Id argument can be a single app ID string...
var singleAppCollector = new Collector('com.instagram.android', { maxPages: 2 });
// ...or an array of app ID strings
var multiAppCollector = new Collector(['com.instagram.android', 'com.facebook.katana'], { maxPages: 2 });

Where the arguments are:

  • App ID (string|string[]): The portion after the id= section of the URL in the Google Play Store (e.g. the app ID for this URL - https://play.google.com/store/apps/details?id=com.google.android.apps.maps&hl=en - would be com.google.android.apps.maps). You can pass a single app ID as a string, or multiple app IDs as an array of strings
  • Options (Object): An object with any (or none) of the following properties:
    • maxPages (Default 5): The maximum number of pages of reviews to parse. Use 0 for unlimited
    • checkBeforeContinue (Default false): When true, the page complete event will have both a continue and a stop function as properties of the object emitted on the event (details below). One of these must be called before the collector will proceed. This is useful when you want to, for example, check to see if the reviews already exist in your database or if they were created in the last X days, etc. Note: When this is set to true, maxPages will be ignored
      • continue() - Keep processing this app if possible
      • stop() - Stop processing this app and move onto the next one, if applicable
    • userAgent (Default Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.85 Safari/537.36): The user agent string to use when making requests
    • delay (Default 5000): The delay (in milliseconds) between page requests
    • maxRetries (Default 3): The maximum number of times to retry a page that could not be parsed before giving up

Listening for Events

Several events are triggered as the Collector parses reviews. You can setup event listeners for these using:

collector.on('<EVENT NAME>', function (result) {
	// Do something with the result every time the event is fired
});

Where the event name is one of:

  • 'review'
    • Fires when: A review is parsed from the page

    • Emits (as an example):

      {
      	os: 'Android', // The OS of the app
      	appId: 'com.instagram.android', // The ID of the app
      	pageNum: 3, // The page that the review was pulled from
      	review: {
      		id: 'gp:AOqpTOHvkDG-YUK...', // The unique review ID
      		date: 'Wed May 25 2016 04:00:00 GMT-0400 (EDT)', // The date of the review (as a Date object)
      		rating: 5, // The star rating given in the review
      		title: 'Great app', // The (optional) title of the review
      		text: 'This app is my most favorite' // The (optional) body of the review
      	}
      }
  • 'page complete'
    • Fires when: A page of reviews has been parsed

    • Emits:

      {
      	os: 'Android', // The OS of the app
      	appId: 'com.instagram.android', // The ID of the app
      	pageNum: 3, // The page that the review was pulled from
      	reviews: [ /* Review objects */ ],
      	firstReviewTime: 'Wed May 23 2016 04:00:00 GMT-0400 (EDT)', // The timestamp of the oldest review on the page (as a Date object)
      	lastReviewTime: 'Wed May 25 2016 04:00:00 GMT-0400 (EDT)', // The timestamp of the newest review on the page (as a Date object)
      	// If the 'checkBeforeContinue' option is set to true:
      	continue: function() {}, // Continue processing reviews for the app
      	stop: function() {} // Stop processing the app
      }
  • 'done collecting'
    • Fires when: The collector has finished collecting reviews for a particular app for one of the following reasons:

      • The collector's maxPages limit is reached for an app
      • The collector reaches the last page of reviews for the app
      • The collector's maxRetries limit is reached for an app
    • Emits:

      {
      	os: 'Android', // The OS of the app
      	appId: 'com.instagram.android', // The ID of the app
      	pageNum: 3, // The page that the review was pulled from
      	appsRemaining: 0, // # of apps left in queue
      	error: undefined || { /* Error object */ }
      }
  • 'done with apps'
    • Fires when: Processing has completed for all of the apps

    • Emits:

      {
      	os: 'Android' // The OS of the app
      }

Starting the Collector

Once you have created an instance of Collector and setup your event listeners, you can begin the collection process using:

collector.collect();

The Collector will then collect reviews until it reaches one of the stop points described in the done collecting event (see above)