🏟️
【LINE API】配信分析APIの使用方法をメモ
今回は、こちらのツイートで紹介したAPIの使用方法について紹介します。
一斉配信の分析API
セグメント配信の分析API
使用方法
API
export const getLineInsight = async (unitId: string, from: string, to: string): Promise<LineInsight | null> => {
const url = 'https://api.line.me/v2/bot/insight/message/event/aggregation'
const params = {
customAggregationUnit: unitId,
from,
to
}
const headers = {
Authorization: `Bearer ${LINE_MESSAGING_CHANNEL_ACCESS_TOKEN}`
}
try {
const { data } = await axios.get(url, {
params,
headers
})
return data
} catch (err) {
console.error(err)
return null
}
}
型
interface LineInsight {
overview: {
uniqueImpression: number | null
uniqueClick: number | null
uniqueMediaPlayed: number | null
uniqueMediaPlayed100Percent: number | null
}
messages: [
{
seq: number
impression: number | null
mediaPlayed: number | null
mediaPlayed25Percent: number | null
mediaPlayed50Percent: number | null
mediaPlayed75Percent: number | null
mediaPlayed100Percent: number | null
uniqueMediaPlayed: number | null
uniqueMediaPlayed25Percent: number | null
uniqueMediaPlayed50Percent: number | null
uniqueMediaPlayed75Percent: number | null
uniqueMediaPlayed100Percent: number | null
}
]
clicks: {
seq: number
url: string
click: number
uniqueClick: number | null
uniqueClickOfRequest: number | null
}[]
}
unitId
というのがLINEドキュメントにも説明があるグループID(ユニット名)のことです。
このIDをセグメント配信ごとに振り分けることで各々の分析が可能になります。
Discussion