Menu
Amazon Mobile Analytics
User Guide

Generating Mobile Analytics Events

Before generating analytics events in your app, you must:

Types of Analytics Events

Information about user engagement in your app is sent to the Mobile Analytics service using events. Generally speaking, there are two types of mobile analytics events:

  • Standard events

  • Custom events

Standard events include those you send to start or stop a session. They also include specialized events used to report on monetization activities in the app, such as in-app purchases. Custom events are those you create to monitor activities specific to your app, such as completing a level in a game, posting to social media, or setting particular app preferences. An app can have up to 1,500 unique custom events.

Session Events

Standard events include those that allow the app to start and end a session in Mobile Analytics. Sessions enable Mobile Analytics to provide the analytics data in the console reports.

To start a session, the app calls the PutEvents action with a session start event. A session start event has an eventType of "_session.start". To end a session, the app sends an HTTP PutEvents request with a session end event. A session end event has an eventType of "_session.stop".

Defining a Monetization Event

When a user of your app makes a purchase, the code that handles the purchase calls the PutEvents action to send a monetization event.

A monetization event has an eventType of "_monetization.purchase", as shown in the following example. It demonstrates how to monetize an event with a price that does not include the currency symbol.

Copy
POST /2014-06-05/events HTTP/1.1 Host: mobileanalytics.us-east-1.amazonaws.com X-Amz-Date: <Date> Authorization: AWS4-HMAC-SHA256 Credential=<access_key>/20140709/us-east-1/mobileanalytics/aws4_request, SignedHeaders=content-length;content-type;host;user-agent;x-amz-client-context;x-amz-date;x-amz-security-token;x-amz-target, Signature=<signature> User-Agent: <User agent string> x-amz-Client-Context: {"client":{"client_id":"<client_id>","app_title":"<app_title>","app_version_name":"<app_version_name>","app_version_code":"<app_version_code>","app_package_name":"<app_package_name>"},"custom":{},"env":{"platform":"<platform>","model":"<model>","make":"<make>","platform_version":"<platform_version>","locale":"<locale>”}} x-amz-security-token: <Security token> Content-Type: application/json Content-Length: <Payload size bytes> Connection: Keep-Alive { "events": [ { "eventType": "_monetization.purchase", "session": { "startTimestamp": "<ISO 8601 date>", "id": "<session id>" }, "timestamp": "<ISO 8601 date>", "attributes": { "_currency": "<ISO 4217 currency code>", "_product_id":"<User specified string>" }, "metrics": { "_quantity": <Purchase quantity, defaults to 1>, "_item_price": <Decimal price> } } ] }

This example demonstrates how to monetize an event with a price that includes the currency symbol. You can use this example with a formatted price.

Copy
POST /2014-06-05/events HTTP/1.1 Host: mobileanalytics.us-east-1.amazonaws.com X-Amz-Date: <Date> Authorization: AWS4-HMAC-SHA256 Credential=<access_key>/20140709/us-east-1/mobileanalytics/aws4_request, SignedHeaders=content-length;content-type;host;user-agent;x-amz-client-context;x-amz-date;x-amz-security-token;x-amz-target, Signature=<signature> User-Agent: <User agent string> x-amz-Client-Context: {"client":{"client_id":"<client_id>","app_title":"<app_title>","app_version_name":"<app_version_name>","app_version_code":"<app_version_code>","app_package_name":"<app_package_name>"},"custom":{},"env":{"platform":"<platform>","model":"<model>","make":"<make>","platform_version":"<platform_version>","locale":"<locale>”}} x-amz-security-token: <Security token> Content-Type: application/json Content-Length: <Payload size bytes> Connection: Keep-Alive { "events": [ { "eventType": "_monetization.purchase", "session": { "startTimestamp": "<ISO 8601 date>", "id": "<session id>" }, "timestamp": "<ISO 8601 date>", "attributes": { "_item_price_formatted": "<Price prefixed with currency symbol ($1.99)>", "_product_id":"<User specified string>" }, "metrics": { "_quantity": <Purchase quantity, defaults to 1> } } ] }

Creating a Custom Event

In addition to the standard events, you can also define your own custom events to report on types of interaction specific to your app, such as finishing levels of a game.

You assign an eventType to your custom event. As a best practice, we recommend you give a general name to a custom event and specific names to attributes or metrics. For example, using "Item Bought" instead of "Item XYZ" as a custom event name helps keep the report from having too many distinct event names that are hard to read and aggregate. This example demonstrates how to define a custom event.

Copy
POST /2014-06-05/events HTTP/1.1 Host: mobileanalytics.us-east-1.amazonaws.com X-Amz-Date: <Date> Authorization: AWS4-HMAC-SHA256 Credential=<access_key>/20140709/us-east-1/mobileanalytics/aws4_request, SignedHeaders=content-length;content-type;host;user-agent;x-amz-client-context;x-amz-date;x-amz-security-token;x-amz-target, Signature=<signature> User-Agent: <User agent string> x-amz-Client-Context: {"client":{"client_id":"<client_id>","app_title":"<app_title>","app_version_name":"<app_version_name>","app_version_code":"<app_version_code>","app_package_name":"<app_package_name>"},"custom":{},"env":{"platform":"<platform>","model":"<model>","make":"<make>","platform_version":"<platform_version>","locale":"<locale>”}} x-amz-security-token: <Security token> Content-Type: application/json Content-Length: <Payload size bytes> Connection: Keep-Alive { "events": [ { "eventType": "sampleEvent", "timestamp": "2014-07-09T03:17:20.041Z", "session": { "id": "<Session id>", "startTimestamp": "2014-07-09T03:15:31.041Z" }, "attributes": {}, "metrics": {} }, { "eventType": "otherEvent", "timestamp": "2014-07-09T03:17:42.772Z", "session": { "id": "<Session id>", "startTimestamp": "2014-07-09T03:15:31.041Z" }, "attributes": { "customAttribute": "someValue" }, "metrics": { "count": 1 } } ] }