# Automating Google Play Store reports with 'gsutil' and Windows PowerShell

*2021-11-04*

> Automate Google Play install and rating reports by Android version with gsutil and Windows PowerShell to help prioritize app testing.

#### Why ([feel free to skip](#how))

As Android developer I have various mobile devices (phones, tablets, watches) with all Android version starting 4.0 (Ice Cream Sandwich, API 14) up to Android 12 (L, API 31). Those devices accompanied by very detailed test scenarios help me ensure best possible user experience :)

{{< figure align="aligncenter" width=625 src="/wp-content/uploads/2021/11/Screenshot-2021-11-03-231007.png" alt="Android test devices" caption="Android test devices" >}}

When prepping release for an app, all test cases for that particular app are performed on each device. For each Android version I keep track of active installs and user rating. Applying that data in the test scenario. This helps me focus more on particular set of for ex. _unhappy users_ running specific OS version.

Below is a screenshot of a test scenario for one of my apps: [GSM Signal Monitor & SIM Card Info](https://play.google.com/store/apps/details?id=paskov.biz.noservice).

{{< figure align="aligncenter" width=625 src="/wp-content/uploads/2021/11/Screenshot-2021-11-03-233257.png" alt="GSM Signal Monitor & SIM Card Info test scenario" caption="GSM Signal Monitor & SIM Card Info test scenario" >}}

Each Android version has number of active installs and rating. Going to Google Play Store dev console and collecting this information by hand is somehow tedious job, so I decided to automate it using ' _Google Cloud Storage Util_' and a bit of _Windows PowerShell_ scripting.

#### How

Our task is to fetch Google Play store monthly reports for app installs and ratings by OS version, filter them and get data that can easily be copy pasted in the ' _Active Installs_' tab of the test scenario.

##### 1\. Cloud Storage bucket ID

Google Play reports, beside dev console can also be accessed via Google Cloud Storage bucket associated with your developer account. You can go to _"Download reports"_, pick the report type you want and select _"Copy Cloud Storage URI"_ next to it.

{{< figure align="aligncenter" width=625 src="/wp-content/uploads/2021/11/Screenshot-2021-11-04-002800.png" alt="" caption="" >}}

The url will look like this

```
gs://< bucket_id >/stats/installs/
```

where _< bucket\_id >_ will be your actual developer account cloud storage bucket. Remember this bucket id. We will be using it later.

##### 2\. Install gsutil

Google provides GSUtil for using cloud storage from the command line. Head over to [https://cloud.google.com/storage/docs/gsutil\_install#expandable-1](https://cloud.google.com/storage/docs/gsutil_install#expandable-1) and follow the installation instructions.

We will be utilizing the _gsutil.cmd_ assuming that the script is available in system _PATH_.

Next we need to authorize gsutil to access our cloud storage data. Follow the instructions on how to [Authenticate stand-alone gsutil](https://cloud.google.com/storage/docs/gsutil_install#creds-gsutil). For 'project-id' use the project ID of the app you want to get reports for. I'm interested in retrieving reports for [GSM Signal Monitor & SIM Card Info](https://play.google.com/store/apps/details?id=paskov.biz.noservice) app so I will be using it's Cloud Storage project id.

{{< figure align="aligncenter" width=625 src="/wp-content/uploads/2021/11/Screenshot-2021-11-04-010041.png" alt="" caption="" >}}

If everything is setup correctly, opening command prompt and typing "gsutil help" should produce result similar to the screenshot below:
{{< figure align="aligncenter" width=625 src="/wp-content/uploads/2021/11/Screenshot-2021-11-04-011205.png" alt="" caption="" >}}

##### 3\. PowerShell magic :)

Script below will fetch installs and ratings reports from Google Play for specific app for the current month. Will get the last date available in the install report, filter both install and rating reports by _'last available date'_ and strip the reports from rows / columns we are not interested in. It will iterate over the active installs and will try to match installs with the ratings.

Replace **$bucketId** and **$appPackageName** with your cloud storage bucket id and your app package name.

Reports fetched from Google Play and the final output will be saved in the current working directory.

Upon execution you will get a report for your app active users/ratings by Android version, based on the data for the last date available in the install report nicely opened in your default text editor.

{{< figure align="aligncenter" width=625 src="/wp-content/uploads/2021/11/Screenshot-2021-11-04-020204.png" alt="" caption="" >}}

P.S: Enable _column selection mode_ in Notepad++ to get only the numbers. Use the arrow keys or your mouse while holding _Shift + Alt_.

P.S1: More info on how to retrieve various reports with gsutil [here](https://support.google.com/googleplay/android-developer/answer/6135870?hl=en#zippy=%2Creviews).

Feel free to modify the script to suit your reporting needs :)

