Developer’s Blog: In-App Purchase Analytics with Python

Abhishek Gokhale
stick.sports
Published in
4 min readMar 15, 2019

In this third installation of our Developer’s Blog series (in case you missed out, read the first and second posts from this series) we’d like to discuss In-App Purchases (IAPs), Analytics and Python (because making games is not just about creating and playtesting but also understanding how our gamers like to play). We’ll walk through two examples of IAP Analytics using Python. The first is a heatmap of IAP transactions created using Pandas and Seaborn. The second is an AWS Lambda Python function for monitoring IAP validation failures.

Before diving into the exciting world of analysing data from in-app purchases, let’s set the scene. An in-app purchase is a significant event in a free-to-play mobile game. The IAP transaction delivers value to the user by unlocking new content or special features whilst allowing the app developer to monetise their app. We want to analyse these transactions because they can reveal insights about user behaviour or transactional anomalies. In terms of tools, we like Python for its versatility, ease of use and rich ecosystem of open-source libraries.

Visualising IAP Transactions

Analysing IAP transactions by day & hour can enable more precise targeting of in-app offers (for example, to schedule promotions on a specific day & hour when more users are more likely to make a purchase). For this purpose, we obtained a sample of timestamped IAP transaction logs from Google Play Store as CSV files and processed them using Pandas. Pandas is our go-to tool for data manipulation and analysis. Ingesting dozens of CSV files into a Dataframe is a breeze with Pandas’ read_csv function wrapped inside of a for-loop. As IAP transactions are often reported in a different timezone to the user’s locale, performing timezone conversions is easy with Pandas’ TimedeltaIndex facility.

After counting transactions grouped by day & time and min-max scaling to [0,1] interval, we can plot the heatmap shown below using Seaborn’s heatmap function. We like Seaborn because it builds on top of Matplotlib with more options for beautiful and eye-catching statistical data visualisations. So for this sample of users, Sundays at 7 PM seem to be the most popular time for IAPs while Sundays at 5 AM seem to be the least popular!

A Seaborn heatmap mapping IAP transactions by day & time for a sample of users

Monitoring Validation Failures

IAP validation failures are important to address not only because failed transactions represent lost revenue for an app developer, but more importantly failed transactions can negatively affect user experience and can impact on user retention. A cloud function is a great way of automating repetitive tasks and works great for monitoring validation failures. The flow of our cloud function is depicted below. We pulled internal validation logs from a SQL database into a Pandas Dataframe with Pandas’ handy read_sql function. Then, we processed them in-memory and sent an output message with basic summary statistics to a designated Slack channel using the Slack Developer Kit for Python.

Finally, the cloud function was set to be triggered every day at a specific time using a cron job service. At the time of writing the Python 3 runtime for AWS Lambda only includes Amazon’s Boto 3 SDK. Other third-party libraries must be included separately in a deployment package file. Since NumPy is a dependency for Pandas (and deployment packages needing NumPy must be built using the same OS as the Lambda environment), we opted to build our deployment package using an Amazon Linux Image inside of a Docker container. Here’s a great blog post with a step-by-step guide that we found helpful.

Flow of our AWS cloud function for monitoring IAP validation failures

In conclusion, analysing IAP transactions can be a worthwhile exercise for app developers because this can uncover hidden and potentially important patterns, instrumental in fixing issues or improving promotions. Python is an incredibly useful tool for Analytics of all shapes and sizes and particularly excels in analysis of time-series data like IAP transactions.

If you’d like to know more about this or want us to discuss a specific topic in our next Developer’s Blog, just leave a comment below!

Abhishek is the Data Analyst at Stick Sports. In his spare time, he enjoys watching TV on-demand, learning new things and sweating it out in the gym.

Have some pressing questions for Abhishek? Join our Telegram group and ask away!

--

--

Abhishek Gokhale
stick.sports

Abhishek is the Data Analyst at Stick Sports. In his spare time he enjoys watching TV on-demand, learning new things and sweating it out in the gym.