Replace deprecated post insights metrics
post_impressions and post_engaged_users are rejected by Graph (#100). Use post_media_view and post_clicks instead. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,21 +33,24 @@ export async function getPageDailyInsights(page: PageCredentials) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Metric names here are unverified against the current Graph version — if
|
||||
* Meta rejects one, swap it and keep `raw` so history can be re-derived.
|
||||
* post_impressions / post_engaged_users / post_impressions_unique are
|
||||
* deprecated ("(#100) The value must be a valid insights metric"; verified
|
||||
* against a live page on 2026-11-29). Replacements: post_media_view (views)
|
||||
* is stored in `impressions`, post_clicks in `engaged`. DB column names are
|
||||
* kept so existing history stays comparable; `raw` keeps the full response.
|
||||
*/
|
||||
export async function getPostInsights(page: PageCredentials, fbPostId: string) {
|
||||
const id = fbPostId.includes("_") ? fbPostId : `${page.fbPageId}_${fbPostId}`;
|
||||
const res = await graphGet(`/${id}/insights`, page.token, {
|
||||
metric: "post_impressions,post_engaged_users,post_reactions_by_type_total",
|
||||
metric: "post_media_view,post_clicks,post_reactions_by_type_total",
|
||||
});
|
||||
const data: InsightMetric[] = res.data ?? [];
|
||||
const reactionsRaw = data.find((d) => d.name === "post_reactions_by_type_total")?.values?.[0]?.value;
|
||||
const reactions =
|
||||
reactionsRaw && typeof reactionsRaw === "object" ? Object.values(reactionsRaw).reduce((a, b) => a + b, 0) : 0;
|
||||
return {
|
||||
impressions: latest(data, "post_impressions"),
|
||||
engaged: latest(data, "post_engaged_users"),
|
||||
impressions: latest(data, "post_media_view"),
|
||||
engaged: latest(data, "post_clicks"),
|
||||
reactions,
|
||||
raw: res,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user