# Get statistics per aggregation unit

You can get statistics of how users interact with push messages and multicast messages you send to multiple users. The user interaction data is aggregated in units you define. As illustrated below, you can get statistics for each unit by assigning a unit name and sending a message.

# Assign a unit name

To aggregate data, you must assign an aggregation unit name to push messages or multicast messages when you send the messages. To assign a unit name to a push or multicast message, specify the name in the customAggregationUnits property of the request body. You can only specify one unit name when you send the messages. For the specification on sending push messages or multicast messages, see Message in the Messaging API reference.

Here is an example request to assign an aggregation unit name, promotion_a, on a push message:

curl -v -X POST https://api.line.me/v2/bot/message/push \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {channel access token}' \
-d '{
    "to": "U4af4980629...",
    "messages":[
        {
            "type": "text",
            "text": "Hello, world1"
        }
    ],
    "customAggregationUnits": [
        "promotion_a"
    ]
}'
Assigning or changing unit name later

You can't assign or change a unit name on a push message or multicast message after you send the message.

When assigning unit names, make the contents of the message bubble consistent

If you send messages with the same unit name, the statistics are aggregated together, regardless of message contents or the number and order of message bubbles. When sending multiple messages with the same unit name, make sure the contents of the message bubbles are consistent.

# Maximum number of unit name types

During the current month (from the 1st to the last day of the month), you can send messages with up to 1,000 different unit names.

For example, if you send messages in March with 1,000 unit name types from promotion_0001 to promotion_1000, you can send messages in the next month (April) with the same 1,000 unit name types from promotion_0001 to promotion_1000. It is also possible to send messages with 1,000 new unit name types, from promotion_1001 to promotion_2000, in the next month (April).

Note that when messages are sent with the 1,001st or later unit name type, those unit names are treated as if they weren't assigned to the messages. For example, if you send messages with 1,500 unit name types from promotion_0001 to promotion_1500, the messages will be sent for the 1,001st unit name type after promotion_1001, but the unit names won't be assigned to the messages.

You can get the number of unit names assigned during this month by using the Get the number of unit name types assigned during this month endpoint.

Regarding the unit name limit

There is a limit of "up to 1,000 unit name types in this month" when assigning unit names, but if you get statistics per unit after sending a message, you can get statistics for all units that exist from from to to for the period covered by the aggregation.

# Get statistics per unit

You can get user interaction statistics for push messages and multicast messages sent with unit names by using the Get statistics per unit endpoint. Here is an example request to get statistics of a unit named promotion_a:

curl -v -X GET https://api.line.me/v2/bot/insight/message/event/aggregation \
-H 'Authorization: Bearer {channel access token}' \
--data-urlencode 'customAggregationUnit=promotion_a' \
--data-urlencode 'from=20210301' \
--data-urlencode 'to=20210331' \
-G

In addition, you can get a list of unit names assigned in this month by using the Get a list of unit names assigned during this month endpoint. There is no endpoint to check unit names assigned before the previous month.