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:
@@ -95,9 +95,9 @@ export default async function InsightsPage() {
|
|||||||
<tr>
|
<tr>
|
||||||
<th>โพสต์</th>
|
<th>โพสต์</th>
|
||||||
<th>เพจ</th>
|
<th>เพจ</th>
|
||||||
<th className="text-right!">Impressions</th>
|
<th className="text-right!">ยอดดู</th>
|
||||||
<th className="text-right!">Engaged</th>
|
<th className="text-right!">คลิก</th>
|
||||||
<th className="text-right!">Reactions</th>
|
<th className="text-right!">รีแอคชัน</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|||||||
@@ -33,21 +33,24 @@ export async function getPageDailyInsights(page: PageCredentials) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metric names here are unverified against the current Graph version — if
|
* post_impressions / post_engaged_users / post_impressions_unique are
|
||||||
* Meta rejects one, swap it and keep `raw` so history can be re-derived.
|
* 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) {
|
export async function getPostInsights(page: PageCredentials, fbPostId: string) {
|
||||||
const id = fbPostId.includes("_") ? fbPostId : `${page.fbPageId}_${fbPostId}`;
|
const id = fbPostId.includes("_") ? fbPostId : `${page.fbPageId}_${fbPostId}`;
|
||||||
const res = await graphGet(`/${id}/insights`, page.token, {
|
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 data: InsightMetric[] = res.data ?? [];
|
||||||
const reactionsRaw = data.find((d) => d.name === "post_reactions_by_type_total")?.values?.[0]?.value;
|
const reactionsRaw = data.find((d) => d.name === "post_reactions_by_type_total")?.values?.[0]?.value;
|
||||||
const reactions =
|
const reactions =
|
||||||
reactionsRaw && typeof reactionsRaw === "object" ? Object.values(reactionsRaw).reduce((a, b) => a + b, 0) : 0;
|
reactionsRaw && typeof reactionsRaw === "object" ? Object.values(reactionsRaw).reduce((a, b) => a + b, 0) : 0;
|
||||||
return {
|
return {
|
||||||
impressions: latest(data, "post_impressions"),
|
impressions: latest(data, "post_media_view"),
|
||||||
engaged: latest(data, "post_engaged_users"),
|
engaged: latest(data, "post_clicks"),
|
||||||
reactions,
|
reactions,
|
||||||
raw: res,
|
raw: res,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user