Skip to content

Commit a283f39

Browse files
committed
Implement getStatisticsPerUnit
1 parent 6fbd25d commit a283f39

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

docs/api-reference/client.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class Client {
8484
getNumberOfFollowers(date: string): Promise<Types.NumberOfFollowersResponse>
8585
getFriendDemographics(): Promise<Types.FriendDemographics>
8686
getUserInteractionStatistics(requestId: string): Promise<Types.UserInteractionStatistics>
87+
getStatisticsPerUnit(customAggregationUnit: string, from: string, to: string): Promise<Types.StatisticsPerUnit>
8788

8889
// AudienceGroup
8990
createUploadAudienceGroup(uploadAudienceGroup: {
@@ -751,6 +752,14 @@ It corresponds to the [Get number of followers](https://developers.line.biz/en/r
751752

752753
It corresponds to the [Get friend demographics](https://developers.line.biz/en/reference/messaging-api/#get-demographic) API.
753754

755+
#### `getUserInteractionStatistics(): Promise<Types.UserInteractionStatistics>`
756+
757+
It corresponds to the [Get user interaction statistics](https://developers.line.biz/en/reference/messaging-api/#get-message-event) API.
758+
759+
#### `getStatisticsPerUnit(): Promise<Types.StatisticsPerUnit>`
760+
761+
It corresponds to the [Get statistics per unit](https://developers.line.biz/en/reference/messaging-api/#get-statistics-per-unit) API.
762+
754763
### Bot
755764

756765
#### `getBotInfo(): Promise<BotInfoResponse>`

lib/client.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,17 @@ export default class Client {
515515
return ensureJSON(res);
516516
}
517517

518+
public async getStatisticsPerUnit(
519+
customAggregationUnit: string,
520+
from: string,
521+
to: string,
522+
): Promise<Types.StatisticsPerUnit> {
523+
const res = await this.http.get<Types.StatisticsPerUnit>(
524+
`${MESSAGING_API_PREFIX}/insight/message/event/aggregation?customAggregationUnit=${customAggregationUnit}&from=${from}&to=${to}`,
525+
);
526+
return ensureJSON(res);
527+
}
528+
518529
public async createUploadAudienceGroup(uploadAudienceGroup: {
519530
description: string;
520531
isIfaAudience?: boolean;

lib/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,6 +2499,20 @@ export type UserInteractionStatistics = {
24992499
clicks: UserInteractionStatisticsOfEachURL[];
25002500
};
25012501

2502+
/**
2503+
* https://developers.line.biz/en/reference/messaging-api/#get-statistics-per-unit
2504+
*/
2505+
export type StatisticsPerUnit = {
2506+
overview: {
2507+
uniqueImpression: number;
2508+
uniqueClick: number;
2509+
uniqueMediaPlayed: number;
2510+
uniqueMediaPlayed100Percent: number;
2511+
};
2512+
messages: UserInteractionStatisticsOfEachMessage[];
2513+
clicks: UserInteractionStatisticsOfEachURL[];
2514+
};
2515+
25022516
type FilterOperatorObject<T> = {
25032517
type: "operator";
25042518
} & (

test/client.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,24 @@ describe("client", () => {
744744
equal(scope.isDone(), true);
745745
});
746746

747+
it("getStatisticsPerUnit", async () => {
748+
const customAggregationUnit = "promotion_a";
749+
const from = "20210301";
750+
const to = "20210331";
751+
const scope = mockGet(
752+
MESSAGING_API_PREFIX,
753+
"/insight/message/event/aggregation",
754+
{
755+
customAggregationUnit,
756+
from,
757+
to,
758+
},
759+
);
760+
761+
await client.getStatisticsPerUnit(customAggregationUnit, from, to);
762+
equal(scope.isDone(), true);
763+
});
764+
747765
it("createUploadAudienceGroup", async () => {
748766
const requestBody = {
749767
description: "audienceGroupName",

0 commit comments

Comments
 (0)