Python data fetcher from https://analytics.itunes.apple.com
Despite of anouncement of a new Apple Analytics API at WWDC 2018 in June'18 (see the video), it's not yet available even in the end of August'18. Hence inspired by the node.js' module itunesconnectanalytics, for my current task, I decided to make a python module to fetch the data from Itunes Analytics App.
The module is made to download csv data files for a given time and metric. It's based on selenium library and uses Chrome WebDriver to emulate real user interacting with the Itunes Analytics App by launching a headless chrome browser (you can easility specify another browser in case it's required).
Steps:
- Login to https://appstoreconnect.apple.com using your credentials from credentials.json
credentials.json structure:
{"user":"[email protected]", "pass":"YOUR_ITUNES_PASS"}
- Access https://analytics.itunes.apple.com with specified metric and time frame
List of metrics:
{"impressions": "impressionsTotalUnique",
"views": "pageViewUnique",
"downloads": "units",
"installs": "installs",
"sessions": "sessions",
"ad": "activeDevices",
"crash": "crashes",
"purchases": "iap",
"bookings": "sales",
"pu": "payingUsers"}
- Download the csv data file from the page on step 2 by emulating a click on the "download" icon
As an example, let's fetch daily installs during July'18 for the application with the itunes ID APPID
Load required modules
import json
import os
from itunes_app_analytics import (Params,
Login,
DataFetcher,
browser)
Read the appstoreconnect.apple.com (itunes) credentials
PATH = os.path.dirname(__file__)
credentials = json.load(open(os.path.join(PATH, 'credentials.json')))
Specify the metrics, time frame and the output folder
# list of metrics
param = Params()
# input parameters
metric = 'downloads'
tframe = 'month'
tview = 'day'
date = '201807'
# output dir
dir_out = '/tmp'
Login into https://appstoreconnect.apple.com
_ = Login(credentials['user'], credentials['pass'])
Launch a data fetcher "instance" and set the output folder
fetcher = DataFetcher
# set the output folder
fetcher.output_dir(download_dir = dir_out)
Download the data and close the browser
downloader = fetcher.download
downloader(APPID, param.measure[metric], param.interval[tframe], param.zoom[tview], date)
browser.close()
Done! We've just automated data extraction from Itunes Analytics.
- Chrome 62+
- Chrome WebDriver (it's provided with the module in the folder browser)
- python3.6 (it'll most likely work on 2.7, but it wasn't tested)
Modules (use requiremenets.txt):
- json >= 2.0.9
- selenium >= 3.13.0