Hi there,
I am using Python SDK to pull async analytics data for campaigns from past for Sep 2021 month.
While active entities API returned 20 campaign associated to my Ads account during Sep 2021 month, async analytics API is only returning stats for 4 campaign.
For recent months, there are no issues.
Am i missing something here? How far historical stats i can pull for campaign using async analytics API?
The Analytics endpoints will return all historical Ads-related metrics for an Ads Account. The Active Entities endpoint will only identify campaign/stats that have changed within the specified window. It is possible that the Active Entities API incorrectly identifies ads entities as updated for a given period and the corresponding analytics requests don’t return any data. The behavior is to over identify rather than miss updates.
Are you stating that the Active Entities API is missing identifying campaigns which should have been returned?
Active entities API are returning correct results for campaings and line items.
However, async analytics API is one which is returning stats for lesser number of campaigns. Also, initially i was having 2 mins of sleep time in below query and it was returning results for just 2 campaigns and when changed it to 10 mins, it returned for 16 campaigns out of 20 (returned by active entities API for Sep 2021). If I go and see in Twitter UI which our marketing team usage , I can see stats for all 20
Below are codes:
#this returns lineItem_Id’s associated with 20 different campaigns when looking in Sep 2021 time frame
active_entities = LineItem.active_entities(account, start_time, end_time)
lineItemId_list = [d[‘entity_id’] for d in active_entities]
#However this async API not returning stats for all 20’s campaigns. sometime just for 4 of them when kept sleep_seconds to 120 and for 16 campaings stats when kept it for 600 seconds waiting.
create async stats jobs and get job ids
queued_job_ids = []
for chunk_ids in split_list(lineItemIds, 20):
queued_job_ids.append(LineItem.queue_async_stats_job(account, chunk_ids, metric_groups, granularity=granularity, placement=placement, start_time=start_time, end_time=end_time, country=country, segmentation_type=segmentation_type).id)
print(queued_job_ids)
# let the job complete
seconds = 120
time.sleep(seconds)
async_stats_job_results = LineItem.async_stats_job_result(account, job_ids=queued_job_ids)
async_data = []
try:
for result in async_stats_job_results:
async_data.append(LineItem.async_stats_job_data(account, url=result.url))
except:
pass
return async_data