pip install mytracker-export-api
In MyTracker, you can use a Python library for even more convenient tracking of data through API requests. You can download raw data, reports, and segments in just a few code lines.
Only account owners and users with the granted export permissions can export raw data and segments from the account. For details, see User management.
Before start working with the Python library:
To install the library:
pip install mytracker-export-api
Find the Python library in the GitHub repository.
Use your API User ID and API Secret Key along with the required raw data parameters, selectors, and events to export raw data:
from mytracker_export_api import MyTracker
API_USER_ID = 123
API_SECRET_KEY = 'AaBbCc'
params = {
'dateFrom': '2022-05-01',
'dateTo': '2022-05-31',
'selectors': 'idAdEventTypeTitle,tsClick,tsView,dtEvent,tsEvent,idPartnerTitle,advertisingId',
'idApp': 2,
'event': 'installs'
}
client = MyTracker(api_user_id=API_USER_ID, api_secret_key=API_SECRET_KEY)
raw_data = client.get_raw_data(params)
raw_data.head()
The result will be returned in Pandas DataFrame by default:
idAdEventTypeTitle | tsClick | tsView | dtEvent | tsEvent | idPartnerTitle | advertisingId | |
---|---|---|---|---|---|---|---|
0 | Unknown | 0 | 0 | 2022-05-31 | 1010101010 | Organic | 00000000-0000-0000-0000-000000000000 |
1 | Unknown | 0 | 0 | 2022-05-30 | 2020202020 | Organic | 00000000-0000-0000-0000-000000000000 |
2 | Unknown | 0 | 0 | 2022-05-31 | 3030303030 | Organic | 00000000-0000-0000-0000-000000000000 |
3 | Unknown | 0 | 0 | 2022-05-14 | 4040404040 | Organic | 00000000-0000-0000-0000-000000000000 |
4 | Unknown | 0 | 0 | 2022-05-29 | 5050505050 | Organic | 00000000-0000-0000-0000-000000000000 |
If you want to save the table as a CSV file, use raw_data.to_csv
:
raw_data.to_csv('raw_data.csv', index=False)
If you want to receive a response from a server and not a default DataFrame, use the return_df=False
value:
response = client.get_raw_data(params, return_df=False)
print(response)
In this case, the response will be the following:
{'code': 200,
'data': {'idRawExport': '11040581',
'status': 'Success!',
'files': [{'link': 'https://somelink.csv.gz',
'timestampExpires': '1655975434'}]},
'message': 'Ok'}
Use the received link to download the raw data file. For details, refer to the Data download section.
If there is an error occurred in a request, then the MyTrackerError
exception with a server response and error details will be requested.
Use your API User ID and API Secret Key along with the required parameters and selectors to export reports:
from mytracker_export_api import MyTracker
API_USER_ID = 123
API_SECRET_KEY = 'AaBbCc'
params = {
'settings[selectors]': 'date,idPartner,sumCampaignCost',
'settings[filter][date][from]': '2022-06-01',
'settings[filter][date][to]': '2022-06-10',
'settings[filter][dimension][idApp][value][]': [1, 2, 3],
'settings[filter][dimension][idPartner][value][]': [10025, 10017],
'settings[idCurrency]': 840,
'settings[tz]': 'Europe/Moscow',
'settings[precision]': 5,
'settings[retIndent]': 3600,
}
client = MyTracker(api_user_id=API_USER_ID, api_secret_key=API_SECRET_KEY)
report = client.get_report(params)
report.head()
To get data for multiple filters, use square brackets 'idApp[]': [1, 2, 3]
or separate values by commas 'idApp': '1,2,3'
.
The result will be returned in Pandas DataFrame by default:
Date | Partner | Campaign cost | |
---|---|---|---|
0 | 2022-06-01 | AppLovin | 33097.9940 |
1 | 2022-06-01 | Unity Ads | 7877.1799 |
2 | 2022-06-02 | AppLovin | 31768.5755 |
3 | 2022-06-02 | Unity Ads | 6858.8901 |
4 | 2022-06-03 | AppLovin | 30292.7189 |
To filter the report by multiple event parameters, index each group of parameters separately:
from mytracker_export_api import MyTracker
API_USER_ID = 123
API_SECRET_KEY = 'AaBbCc'
params = {
'settings[selectors]': 'date,customEventParamValue,uniqEvent',
'settings[filter][date][from]': '2021-07-01',
'settings[filter][date][to]': '2021-07-06',
'settings[filter][dimension][idApp][value]': '12345,12346',
'settings[filter][dimension][isVerified][value]': '1,255',
'settings[filter][dimension][customEventName][value]': 'params',
'settings[filter][dimension][params][name][0]': 'current_id',
'settings[filter][dimension][params][cmp][0]': 'contains',
'settings[filter][dimension][params][value][0]': 'details',
'settings[filter][dimension][params][name][1]': 'id',
'settings[filter][dimension][params][cmp][1]': 'exist',
'settings[filter][dimension][params][value][1]': '',
'settings[filter][dimension][params][name][2]': 'type',
'settings[filter][dimension][params][cmp][2]': 'equals',
'settings[filter][dimension][params][value][2]': 'offer',
'settings[filter][dimension][params][target]': 'params',
'settings[filter][dimension][params][join]': 'and',
'settings[tz]': 'Europe/Moscow',
'settings[precision]': 2,
'settings[retIndent]': 3600,
}
client = MyTracker(api_user_id=API_USER_ID, api_secret_key=API_SECRET_KEY)
report = client.get_report(params)
report.head()
If you want to save the table as a CSV file, use report.to_csv
:
report.to_csv('report.csv', index=False)
If you want to receive a response from a server and not a default DataFrame, use the return_df=False
value:
response = client.get_report(params, return_df=False)
print(response)
In this case, the response will be the following:
{'code': 200,
'data': {'idReportFile': '1394792',
'status': 'Success!',
'files': [{'link': 'https://somelink.csv.gz',
'timestampExpires': '1655977002'}]},
'message': 'Ok'}
Use the received link to download the report file. For details, refer to the Data download section.
If there is an error occurred in a request, then the MyTrackerError
exception with a server response and error details will be requested.
Use your API User ID and API Secret Key along with the required parameters to export segments:
from mytracker_export_api import MyTracker
API_USER_ID = 123
API_SECRET_KEY = 'AaBbCc'
params = {
'idSegment': 1111,
'requestFields': 'idfa,gaid',
'includeHeaderLine': 1,
'registerType': 0,
'hashType': 0
}
client = MyTracker(api_user_id=API_USER_ID, api_secret_key=API_SECRET_KEY)
response = client.get_segment(params)
print(response)
When exporting segments, you receive only a response from a server:
{'code': 200,
'data': {'idSegmentExport': '16',
'status': 'Success!',
'files': [{'link': 'https://somelink.csv.gz',
'timestampExpires': '1655392109'}]},
'message': 'Ok'}
Use the received link to download the segment file. For details, refer to the Data download section.
If there is an error occurred in a request, then the MyTrackerError
exception with a server response and error details will be requested.