This blog in the form of documentation provides a comprehensive guide on automating the process of extracting Google Play Store data, parsing it, and integrating it into Mixpanel using Node.js. By following these steps, you can streamline the process of analyzing app data and use Mixpanel for advanced analytics and insights.
The steps include setting up Google Cloud Storage, fetching data, converting it into a usable format, and sending the data to Mixpanel.
To complete this integration, you will need:
The Google Play Developer API allows you to programmatically access Google Play Store data.
Here’s how to enable it:
Enabling this API allows access to Google Play Store data through Google Cloud services, which is essential for automating data extraction.
You will need a service account to access Google Cloud Storage. Follow these steps:
To enable the service account to access the Google Play Console, follow these steps:
Note: The sync process can take up to 24 to 48 hours until the service account is fully integrated.
Check the Files in the Storage Bucket:
Identify the Required File: Locate reports like installs_com.exampleapp_202410_overview.csv (example name).
Create a script to download the CSV file:
require('dotenv').config();
const { Storage } = require('@google-cloud/storage');
const path = require('path');
const storage = new Storage({
keyFilename: process.env.GOOGLE_
CLOUD_
KEYFILE,
});
const getAppStatsFile = async () => {
try {
const date = new Date();
const year = date.getFullYear().toString();
const month = (date.getMonth() + 1).toString().padStart(2,
'0');
const bucketName = 'pubsite
_prod
_
xx123456789'; // Replace with
your actual bucket name
const fileName=
`installs
_
com.exampleapp_${year}${month}_
overview.csv
`
;
const filePath =
`
stats/installs/${fileName}`
;
const destination = path.join(__
dirname,
`/reports/${fileName}`);
await storage.bucket(bucketName).file(filePath).download({
destination});
console.log('File downloaded successfully to:'
, destination);
return destination;}
catch (error) {
console.error('Error downloading file:'
, error.message);
}
};
getAppStatsFile();
Add Parsing Logic:
const fs = require('fs');
const csv = require('csv-parser');
const readCsvFile = async (filePath) => {
const results = [];
fs.createReadStream(filePath, { encoding: 'utf16le' })
.pipe(csv({ separator: '
'
,
, headers: true }))
.on('data'
, (row) => {
results.push(row);
})
.on('error'
, (error) => {
console.error('Error reading CSV file:'
, error.message);
})
.on('end'
, () => {
console.log('CSV Data Parsed:'
, results);
uploadToMixpanel(results); // Proceed with the Mixpanel
integration.
});
};
getAppStatsFile().then(readCsvFile);
MIXPANEL_
PROJECT
_
TOKEN=your
_project_
token
_
here
MIXPANEL
_
SECRET=your_
secret_
key_
here
const mixpanel = require('mixpanel');
const mixpanelImporter =mixpanel.init(process.env.MIXPANEL PROJECT__TOKEN, {secret: process.env.MIXPANEL_SECRET, });
const uploadToMixpanel = (data) => { data.forEach(item => { const eventName = 'Install Stats'; const dateStr = item['_0']; // Adjust according to your CSV structure.
const time = new Date(dateStr).getTime();
const properties = {time: time, platform: 'android', activeDeviceInstalls: item['_8'], };
mixpanelImporter.import(eventName, time, properties, (err) =>
{ if (err) {
console.error(`Error sending event to Mixpanel: ${err}`);}
else { console.log(`Event tracked successfully: ${eventName}`, properties);}
}); }); };
getAppStatsFile().then(readCsvFile);
By following this guide, you can automate the process of extracting Google Play Store data, parsing it into a usable format, and integrating it with Mixpanel for deeper insights. This setup allows you to gain valuable analytics, enabling data-driven decisions for your app's success.
how it looks