Skip to content

Commit

Permalink
Merge pull request #594 from gitroomhq/feat/instagram-analytics-fix
Browse files Browse the repository at this point in the history
Instagram analytics fix
  • Loading branch information
nevo-david authored Feb 7, 2025
2 parents d51196c + 379704c commit 43910d8
Showing 1 changed file with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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 = [];

return (
data?.map((d: any) => ({
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 }) {
Expand Down

0 comments on commit 43910d8

Please sign in to comment.