You can use the Amazon Pinpoint SDK to report usage data, or events, to Pinpoint. You can report events to capture information such as session times, users' purchasing behavior, sign-in attempts, or any custom event type that you need. After your application reports events, you can view analytics in the Pinpoint console. The charts on the Analytics page provide metrics for many aspects of user behavior. For more information, see [Chart Reference for Amazon Pinpoint Analytics](https://docs.aws.amazon.com/pinpoint/latest/userguide/analytics-charts.html) in the _Amazon Pinpoint User Guide_. To analyze and store your event data outside of Pinpoint, you can configure Pinpoint to stream the data to Amazon Kinesis. For more information, see [Streaming Amazon Pinpoint Events to Kinesis](https://docs.aws.amazon.com/pinpoint/latest/developerguide/analytics-streaming.html). By using the AWS Mobile SDKs and the AWS Amplify JavaScript libraries, you can call the Pinpoint API to report the following types of events: ## Session events Indicate when and how often users open and close your app. After your application reports session events, use the **Analytics** page in the Amazon Pinpoint console to view charts for **Sessions, Daily active endpoints, 7-day retention rate**, and more. These are automatically recorded when you integrate your iOS app with the Pinpoint SDK as shown above. ## Custom events Are nonstandard events that you define by assigning a custom event type. You can add custom attributes and metrics to a custom event. On the **Analytics** page in the console, the **Events** tab displays metrics for all custom events that are reported by your app. Use graphs of your custom usage event data in the Pinpoint console. Visualize how your users' behavior aligns with a model you design using [Amazon Pinpoint Funnel Analytics](https://docs.aws.amazon.com/pinpoint/latest/userguide/analytics-funnels.html), or use [stream the data](https://docs.aws.amazon.com/pinpoint/latest/userguide/analytics-streaming.html) for deeper analysis. Use the following steps to implement Pinpoint custom analytics for your app. ```swift // You can add this function in desired part of your app. // It will be used to log events to the backend. func logEvent() { if let analyticsClient = pinpoint?.analyticsClient { let event = analyticsClient.createEvent(withEventType: "EventName") event.addAttribute("DemoAttributeValue1", forKey: "DemoAttribute1") event.addAttribute("DemoAttributeValue2", forKey: "DemoAttribute2") event.addMetric(NSNumber(value: arc4random() % 65535), forKey: "EventName") analyticsClient.record(event) analyticsClient.submitEvents() } } ``` Build, run, and use your app. Then, view your custom events on the `Events` tab of the Pinpoint console (choose `Analytics`>`Events`). Look for the name of your event in the `Events` menu. ## Monetization events Report the revenue that's generated by your application and the number of items that are purchased by users. On the **Analytics** page, the **Revenue** tab displays charts for **Revenue, Paying users, Units sold**, and more. Use the following steps to implement Pinpoint monetization analytics for your app. ```swift func sendMonetizationEvent() { if let analyticsClient = pinpoint?.analyticsClient { let event = analyticsClient.createVirtualMonetizationEvent( withProductId: "DEMO_PRODUCT_ID", withItemPrice: 1.00, withQuantity: 1, withCurrency: "USD" ) analyticsClient.record(event) analyticsClient.submitEvents() } } ``` ## Authentication events Indicate how frequently users authenticate with your application. On the **Analytics** page, the **Users** tab displays charts for **Sign-ins, Sign-ups, and Authentication failures**. To learn how frequently users authenticate with your app, update your application code so that Pinpoint receives the following standard event types for authentication: * `_userauth.sign_in` * `_userauth.sign_up` * `_userauth.auth_fail` You can report authentication events by doing either of the following: * Managing user sign-up and sign-in with Amazon Cognito user pools. Cognito user pools are user directories that make it easier to add sign-up and sign-in to your app. As users authenticate with your app, Cognito reports authentication events to Pinpoint. For more information, see [Using Amazon Pinpoint Analytics with Amazon Cognito User Pools](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-pinpoint-integration.html) in the _Amazon Cognito Developer Guide_. Also update **awsconfiguration.json** by adding the `PinpointAppId` key under `CognitoUserPool`. ```json "CognitoUserPool": { "Default": { "PoolId": "", "AppClientId": "", "Region": "", "PinpointAppId": "" } } ``` * Reporting authentication events by using the Pinpoint client that's provided by the AWS Mobile SDK for iOS or Android. If you don't want to use Cognito user pools, you can use the Pinpoint client to record and submit authentication events, as shown in the following examples. In these examples, the event type is set to `_userauth.sign_in`, but you can substitute any authentication event type. ```swift func sendUserSignInEvent() { if let analyticsClient = pinpoint?.analyticsClient { let event = analyticsClient.createEvent(withEventType: "_userauth.sign_in") analyticsClient.record(event) analyticsClient.submitEvents() } } ``` ## Event Ingestion Limits The limits applicable to the ingestion of events using the AWS iOS SDK for Pinpoint and the Pinpoint Events API can be found [here](https://docs.aws.amazon.com/pinpoint/latest/developerguide/limits.html#limits-events). Note: Cognito User Pools only supports sending events to Amazon Pinpoint projects in the US East (N. Virginia) us-east-1 Region, regardless of the region in which the user pool resides.