この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
Endpoint とは
Amazon Pinpoint (以降 Pinpoint) は、セグメントされたプッシュ通知をモバイルアプリに送信するためのサービスです。概要については下記の記事を参考にしてください。
Pinpoint では、ターゲッティングの対象となるデバイスを Endpoint と呼んでいます。Endpoint には、デバイスの情報やセグメントのルールとなるカスタム属性値などを含めることができます。本記事では、Pinpoint のログを元に Endpoint の情報を取得してみました。
Endpoint の登録
まずはじめに、Endpoint はどのように登録するかと言う話です。通常は、モバイルアプリから Endpoint を作成するリクエストを AWS SDK 経由で投げることで作ります。概ね、次のような感じです。
// 初期化
pinpoint = [AWSPinpoint pinpointWithConfiguration:[AWSPinpointConfiguration defaultPinpointConfigurationWithLaunchOptions:launchOptions]];
// カスタム属性値の追加
[[pinpoint.targetingClient addAttribute:@[@"Lakers",@"Clippers"] forKey:@"favoriteTeams"];
[pinpoint.targetingClient updateEndpointProfile];
// カスタムイベントの送信
AWSPinpointEvent *event = [pinpoint.analyticsClient createEventWithEventType:@"MyCustomEvent"];
[event addAttribute:@"MyAttributeValue1" forKey:@"MyAttribute1"];
[event addAttribute:@"MyAttributeValue2" forKey:@"MyAttribute2"];
[event addMetric:[NSNumber numberWithInt:(arc4random() % 65535)] forKey:@"MyMetric"];
[pinpoint.analyticsClient recordEvent:event];
[pinpoint.analyticsClient submitEvents];
既にリリース済みのアプリについても配慮されており、最大500件のエンドポイントが追加することができる API も提供されています。
Export の設定
Pinpoint では、Endpoint から送信されたイベントデータを S3 に Export (出力) することができます。
Pinpoint は Amazon Mobile Analytics (以降 Mobile Analytics) と密接に連係しており、Mobile Analytics で作成した App はそのまま Pinpoint の App として利用することができます。そして、Export の設定も Amazon Mobile Analytics の設定と共通です *1。
Mobile Analytics の Export の設定ウィザードでは、IAM の Policy と Role を自動的に作成してくれるので、こちらの方が手軽なのでオススメです。設定方法は以下をご参照ください。
Mobile Analytics 側では、下記のように設定しておきます。
Pinpoint の設定画面を見てみると、同じ設定になっています。
S3 では bucket-name/awsma/events/appId/YYYY/MM/DD/hh/appId-mm-part-partNum-hexCode.gz
の階層で格納されます。
Pinpoint 上では、データは90日間まで保持されます。90日間以上経過しているログを参照するには S3 への Auto Export を有効化しましょう。
Endpoint の情報を取得する
S3 に保存されたイベントのデータを見てみましょう。適当なファイルをダウンロード&解凍し、下記のコマンドで見てみます。
$ cat xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-35-part-0001-aacc04c54f29cae344f89968a5c4e83e | jq .
この中にある client_id
が、Pinpoint で言う Endpoint の ID です。
{
"event_type": "DemoCustomEvent",
"event_timestamp": 1481211057896,
"arrival_timestamp": 1481211058630,
"event_version": "3.0",
"application": {
"app_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"cognito_identity_pool_id": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"package_name": "com.amazon.MySampleApp",
"sdk": {
"name": "aws-sdk-iOS",
"version": "2.4.14"
},
"title": "Unknown",
"version_name": "1.0",
"version_code": "1"
},
"client": {
"client_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"cognito_id": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
"device": {
"locale": {
"code": "en_US",
"country": "US",
"language": "en"
},
"make": "apple",
"model": "iPhone",
"platform": {
"name": "iOS",
"version": "10.1"
}
},
"session": {
"session_id": "xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxxx",
"start_timestamp": 1481211042594
},
"attributes": {
"DemoAttribute2": "DemoAttributeValue2",
"DemoAttribute1": "DemoAttributeValue1"
},
"metrics": {
"DemoMetric": 24979
}
}
この Endpoint ID を元に、AWS CLI から get-endpoint を呼び出してみましょう。
$ aws pinpoint get-endpoint \
--region us-east-1 \
--application-id xxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
--endpoint-id XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX | jq .
Endpoint に関する詳細な情報が取得できました。
{
"EndpointResponse": {
"EffectiveDate": "2016-12-09T01:38:07.155Z",
"OptOut": "NONE",
"RequestId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"Demographic": {
"Locale": "ja_US",
"Make": "apple",
"AppVersion": "1.0",
"Platform": "ios",
"PlatformVersion": "10.1.1",
"Timezone": "Asia/Tokyo",
"Model": "iPhone"
},
"Metrics": {},
"Location": {
"Country": "US"
},
"Address": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"CohortId": "17",
"Attributes": {
"seasons": [
"Summer"
]
},
"ChannelType": "APNS",
"CreationDate": "2016-12-09T01:38:07.155Z",
"ApplicationId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"EndpointStatus": "ACTIVE"
}
}
どのようなデータが入っているかはこちらを参考にしてください。個人的には Address
にデバイストークンが入っているところが嬉しかったです。
まとめ
現状では1件ずつしか見ることはできませんが、Pinpoint に保存した Endpoint の情報を取得できることが確認できました。いろいろな用途に活用できそうです。
参考
- Amazon Pinpoint Documentation
- Integrating Amazon Pinpoint With iOS Apps - Amazon Pinpoint
- Integrating Amazon Pinpoint With Android Apps - Amazon Pinpoint
- Exporting Analytics - Amazon Pinpoint
- Endpoints - Amazon Pinpoint
脚注
- 将来的に変更される可能性がある点にご留意ください。 ↩