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:
credentials.json structure:
{"user":"YOUR_USER@icloud.com", "pass":"YOUR_ITUNES_PASS"}
List of metrics:
{"impressions": "impressionsTotalUnique",
"views": "pageViewUnique",
"downloads": "units",
"installs": "installs",
"sessions": "sessions",
"ad": "activeDevices",
"crash": "crashes",
"purchases": "iap",
"bookings": "sales",
"pu": "payingUsers"}
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.
Modules (use requiremenets.txt):