Skip to content

Commit 43910d8

Browse files
authored
Merge pull request #594 from gitroomhq/feat/instagram-analytics-fix
Instagram analytics fix
2 parents d51196c + 379704c commit 43910d8

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts

+31-5
Original file line numberDiff line numberDiff line change
@@ -383,21 +383,47 @@ export class InstagramProvider
383383
const since = dayjs().subtract(date, 'day').unix();
384384

385385
const { data, ...all } = await (
386-
await fetch(
387-
`https://graph.facebook.com/v20.0/${id}/insights?metric=follower_count,impressions,reach,profile_views&access_token=${accessToken}&period=day&since=${since}&until=${until}`
386+
await this.fetch(
387+
`https://graph.facebook.com/v20.0/${id}/insights?metric=follower_count,impressions,reach&access_token=${accessToken}&period=day&since=${since}&until=${until}`
388+
)
389+
).json();
390+
391+
const { data: data2, ...all2 } = await (
392+
await this.fetch(
393+
`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}`
388394
)
389395
).json();
396+
const analytics = [];
390397

391-
return (
392-
data?.map((d: any) => ({
398+
analytics.push(
399+
...(data?.map((d: any) => ({
393400
label: d.title,
394401
percentageChange: 5,
395402
data: d.values.map((v: any) => ({
396403
total: v.value,
397404
date: dayjs(v.end_time).format('YYYY-MM-DD'),
398405
})),
399-
})) || []
406+
})) || [])
407+
);
408+
409+
analytics.push(
410+
...data2.map((d: any) => ({
411+
label: d.title,
412+
percentageChange: 5,
413+
data: [
414+
{
415+
total: d.total_value.value,
416+
date: dayjs().format('YYYY-MM-DD'),
417+
},
418+
{
419+
total: d.total_value.value,
420+
date: dayjs().add(1, 'day').format('YYYY-MM-DD'),
421+
},
422+
],
423+
}))
400424
);
425+
426+
return analytics;
401427
}
402428

403429
music(accessToken: string, data: { q: string }) {

0 commit comments

Comments
 (0)