I am working on query ads metrics via the Meta business API.
act_$accountId/insights?level=ad&breakdowns=hourly_stats_aggregated_by_advertiser_time_zone&action_report_time=mixed&action_breakdowns=action_type&action_attribution_windows=7d_click,1d_view&fields=campaign_id,adset_id,ad_id,impressions,spend,actions,video_continuous_2_sec_watched_actions,video_p25_watched_actions,video_p75_watched_actions,video_p100_watched_actions&time_ranges=[{"since":"2022-12-05","until":"2022-12-26"}]&limit=20&locale=en_US
For video ads, I need to query a few below metrics,
video_continuous_2_sec_watched_actions,
video_p100_watched_actions
and other video metrics.
They are all List<AdsActionStats> type,
My question is how to parse List<AdsActionStats> ?
For example, for video_continuous_2_sec_watched_actions metric
Option 1: Could I just iterate List<AdsActionStats> and sum each AdsActionStats.value?
Option 2: Or do I need to filter AdsActionStats.ActionType/ActionVideoType?
if so I did not find ActionType for video_continuous_2_sec_watched_actions at https://developers.facebook.com/docs/marketing-api/reference/ads-action-stats/
Is anyone familiar with Meta business API that could provide some suggestions?
Related
We parse our streaming server logs and post as events using the Measurement Protocol in Google Universal Analytics. I having a hard time finding how or if this could work in GA4. Here is an example post we POST using curl from a PHP script for someone listening to one of our HD channels:
v=1&tid=UA-123456789-1&cid=a76-b177-b238-b39d-634225a16b6e&ds=web&ua=AppleCoreMedia%2F1.0.0.19G71%20%28iPad;%20U;%20CPU%20OS%2015_6%20like%20Mac%20OS%20X;%20&ul=en-us&uip=1.2.3.4&cs=event&cn=station&cm=stream&ck=WXYZ%20HD3%20The%20Channel&t=event&ec=Stream&ea=Listen&el=WXYZ%20HD3%20The%20Channel&ev=10&cg1=Hour10&cg2=channel&cg3=Midday%20Weekdays%209am-1pm
We can then view these Events under Behaviors in Universal Analytics in our Event Category of Stream. I wrote this script using the Measurement Protocol parameter reference that clearly now shows a link to the Measurement Protocol in GA4 at the top of the page, but there is no similar parameter reference guide. As you can see, we've posted all mainly to categories, actions and labels even with custom groups.
Here is another for someone listening to a show that POSTS to campaign source/media events:
v=1&tid=UA-123456789-1&cid=a97-b76-b210-b2d-634225a16b6e&ds=web&ua=Mozilla%2F5.0%20%28Windows%20NT%2010.0;%20Win64;%20x64%29%20AppleWebKit%2F537.36%20%28KH&ul=en-us&uip=1.2.3.4&cs=event&cn=station&cm=stream&ck=The%20Show&t=event&ec=Stream&ea=Listen&el=The%20Show&ev=10&cg1=Hour1&cg2=podcast&cg3=Midday%20Weekdays%209am-1pm
Could someone be so kind to point me in the right direction if this is possible to convert to GA4 events?
Here is how you can translate an event in Universal Analytics to GA4:
Universal Analytics
Google Analytics 4
action (ea)
Maps to event_name
event_category (ec)
Maps to an event_category parameter with a parameter value
event_label (el)
Maps to an event_label parameter with a parameter value
event_value (ev)
Maps to an event_value parameter with a parameter value
Using your example, this is what the GA4 event would look like
gtag('event', 'Listen', { 'event_category': 'Stream', 'event_label': 'The Show', 'event_value': '10' });
For more information, refer to this Google help center article.
When trying to fetch Facebook insights API for the following action offsite_conversion.fb_pixel_purchase I always get less number than Facebook show on their ad manager, I tried to inspect their network calls and URL structure and I see they're using the same field offsite_conversion.fb_pixel_purchase to show Results I am not sure why the numbers are mis-matching. I tried to query from the Graph API and from my shell with the same results.
You may check use_account_attribution_setting and use_unified_attribution_setting in here: https://developers.facebook.com/docs/marketing-api/reference/ad-campaign-group/insights
Setting use_unified_attribution_setting to true worked for me.
I did some testing and found out that if you use an additional breakdown, FB will return less conversions. There might be a bug in their API when you use breakdowns.
I tried getting offsite_conversion.fb_pixel_purchase with
'breakdowns' => 'hourly_stats_aggregated_by_advertiser_time_zone',
and facebook retuned 5 conversions.
if I remove the breakdown and get the data grouped daily I get 11 conversions which is what Facebook Ads Manager shows
I am doing REST API call to get source data which is JSON and file size is around 1GB. I would like to use pagination concept. I see in this link https://learn.microsoft.com/en-us/answers/questions/59467/how-to-pass-pagination-rules-during-a-rest-api-cal.html?childToView=256118#answer-256118 where it uses Web activity to get the total page. But how? any advise!
My sink is COSMOS DB
According to your link, I think we only can make a web call to find out the total pages. In other words, the total pages is from your REST API. Then we can use an Array type variable to store the response.
I'm trying to collect all the posts of my company page with this kind of query
https://graph.facebook.com/v2.2//feed?limit=250&fields=id,type,status_type,comments{id},likes{id},shares
Problem is that I'm not collecting all posts.
I will have a better result with limit=20 and some time with limit=100
Most of the pages (from the pagination mechanism point of view) will not have 100 items.
I know some posts may not be exposed because of privacy settings.
My issue is that a call with limit=20 is not returning once going through pagination the same amount of data as limit=250.
How could it be?
How providers of Facebook Analytics can garanty the quality of data they collect ?
The Facebook graph api only allow the max of 100 items per request, despite you specify more than that.
Afaik the limit parameter is indeed buggy. But 250 would be a very high value, there is a max value for the parameter too - i assume it depends on the API call how high it is, could be fixed too.
Better donĀ“t use limit at all and use paging to get more results: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging
I'm attempting to make a Facebook app that will query insights metrics from pages that I administer. I'm unsure if there is a better approach, but I am running into issue after issue trying to build my queries.
For instance, many of the "metric" fields listed here return empty data objects. Testing the following FQL query on the Graph API Explorer is an example (substitute with your page ID):
fql?q=SELECT metric, value FROM insights WHERE object_id=<USER_ID> AND metric='post_storytellers' AND period=0
I have granted myself "read_insights" permissions.
I'm wondering if this is a common issue, if I'm doing this wrong, and if there is a better way (i.e. FQL is problematic, stick to the Graph API). I started this project using Perl, intending to simply parse the return data into a database. Perhaps I would be better served writing this in PHP?
The post_storytellers metric, has only 3 available periods: day, week and days_28. When you put period=0, you are asking for the lifetime period.
Your query should be something like this:
SELECT metric, value FROM insights WHERE object_id=<PAGE_ID> AND metric='page_storytellers' AND end_time=1334905200 AND period=period('week')
I hope it would help!