fix(facebook): use live post insight metrics and read Reels from /video_insights - #320
Open
maciejdzierzek wants to merge 1 commit into
Open
fix(facebook): use live post insight metrics and read Reels from /video_insights#320maciejdzierzek wants to merge 1 commit into
/video_insights#320maciejdzierzek wants to merge 1 commit into
Conversation
…eo_insights
Two separate breakages in Graph API v25:
1. Feed posts asked for the retired `post_impressions` / `post_impressions_unique`
pair. Including a retired metric fails the whole request, so no metrics came
back at all. Replaced with the current names: `post_media_view` (views) and
`post_total_media_view_unique` (reach).
2. Facebook Reels have no /insights edge at all, so every Reel returned an error.
Their metrics live on /video_insights, which returns a sensible default set
when called without a `metric` parameter.
Also maps raw metric names to the same readable labels the other analytics
services use (Reach / Views / Likes / Clicks), instead of ucfirst() on the raw
Graph key - the new names do not read well otherwise ("Post total media view
unique").
Reel reaction counts arrive as a dictionary keyed by reaction type, so those
values are summed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Facebook posts currently return no metrics, for two independent reasons in Graph API v25. Companion to #319 (same problem class on Instagram).
1. Feed posts ask for retired metrics
post_impressionsandpost_impressions_uniquewere retired. A retired name does not get skipped — it fails the whole request, so the other metrics in the same call (post_reactions_like_total,post_clicks) never arrive either.Current equivalents:
post_impressionspost_media_viewpost_impressions_uniquepost_total_media_view_unique2. Facebook Reels have no
/insightsedgeEvery Reel errored out, because Reels expose their metrics on
/video_insightsinstead. Called without ametricparameter that edge returns a sensible default set (blue_reels_play_count,post_impressions_unique,post_video_avg_time_watched, and others), which is what this PR reads.Reaction counts there come back as a dictionary keyed by reaction type, so those values are summed into a single number.
Labels
The raw v25 metric names do not survive
ucfirst(str_replace(...))—post_total_media_view_uniquerenders as "Post total media view unique". This maps them to the same vocabulary the other analytics services already use: Reach / Views / Likes / Clicks, plus Plays / Replays / Avg watch time for Reels.How I verified
Probed both edges against live Business assets on v25. Calling the insights edge without a
metricparameter returns the default set, and passing a retired name returns an error listing the permitted metrics — that is how the replacement names above were established rather than guessed.Running in production since 2026-08-04. Before: every Facebook post reported an API error. After: reach and views populate for both feed posts and Reels.