Merge pull request #594 from gitroomhq/feat/instagram-analytics-fix

Instagram analytics fix
This commit is contained in:
Nevo David 2025-02-07 18:33:35 +07:00 committed by GitHub
commit 43910d8370
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 31 additions and 5 deletions

View File

@ -383,21 +383,47 @@ export class InstagramProvider
const since = dayjs().subtract(date, 'day').unix();
const { data, ...all } = await (
await fetch(
`https://graph.facebook.com/v20.0/${id}/insights?metric=follower_count,impressions,reach,profile_views&access_token=${accessToken}&period=day&since=${since}&until=${until}`
await this.fetch(
`https://graph.facebook.com/v20.0/${id}/insights?metric=follower_count,impressions,reach&access_token=${accessToken}&period=day&since=${since}&until=${until}`
)
).json();
return (
data?.map((d: any) => ({
const { data: data2, ...all2 } = await (
await this.fetch(
`https://graph.facebook.com/v20.0/${id}/insights?metric_type=total_value&metric=likes,comments,shares,saves,replies&access_token=${accessToken}&period=day&since=${since}&until=${until}`
)
).json();
const analytics = [];
analytics.push(
...(data?.map((d: any) => ({
label: d.title,
percentageChange: 5,
data: d.values.map((v: any) => ({
total: v.value,
date: dayjs(v.end_time).format('YYYY-MM-DD'),
})),
})) || []
})) || [])
);
analytics.push(
...data2.map((d: any) => ({
label: d.title,
percentageChange: 5,
data: [
{
total: d.total_value.value,
date: dayjs().format('YYYY-MM-DD'),
},
{
total: d.total_value.value,
date: dayjs().add(1, 'day').format('YYYY-MM-DD'),
},
],
}))
);
return analytics;
}
music(accessToken: string, data: { q: string }) {