Skip to content

Add Auth Pinpoint events to Amplify docs, not just SDK #4780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions src/fragments/lib-v1/analytics/android/record.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ Events have default configuration to flush out to the network every 30 seconds.
"awsPinpointAnalyticsPlugin": {
"pinpointAnalytics": {
"appId": "AppID",
"region": "Region"
"region": "Region",
"autoFlushEventsInterval": 10000
},
"pinpointTargeting": {
"region": "Region"
},
"autoFlushEventsInterval": 10000
}
}
}
}
Expand Down Expand Up @@ -101,6 +101,60 @@ RxAmplify.Analytics.flushEvents();
</Block>
</BlockSwitcher>

## Authentication events

import native_common from "/src/fragments/lib-v1/analytics/native_common/getting-started/auth-events.mdx";

<Fragments fragments={{all: native_common}} />

<BlockSwitcher>
<Block name="Java">

```java
/**
* Call this method to log an authentication event to the analytics client.
*/
public void logAuthenticationEvent() {
AnalyticsEvent event = AnalyticsEvent.builder()
.name("_userauth.sign_in")
.build();
Amplify.Analytics.recordEvent(event);
}
```

</Block>
<Block name="Kotlin">

```kotlin

/**
* Call this method to log an authentication event to the analytics client.
*/
fun logAuthenticationEvent() {
val event = AnalyticsEvent.builder()
.name("_userauth.sign_in")
.build()
Amplify.Analytics.recordEvent(event)
}
```
</Block>
<Block name="RxJava">

```java

/**
* Call this method to log an authentication event to the analytics client.
*/
public void logAuthenticationEvent() {
AnalyticsEvent event = AnalyticsEvent.builder()
.name("_userauth.sign_in")
.build();
RxAmplify.Analytics.recordEvent(event);
}
```
</Block>
</BlockSwitcher>

## Global Properties

You can register global properties which will be sent along with all invocations of `Amplify.Analytics.recordEvent`.
Expand Down
17 changes: 16 additions & 1 deletion src/fragments/lib-v1/analytics/ios/record.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Record Event

The Amplify Analytics plugin provides a simple interface to record custom events within your app. The plugin handles retry logic in the event the device looses network connectivity, and automatically batches requests to reduce network bandwidth.
The Amplify Analytics plugin provides a simple interface to record custom events within your app. The plugin handles retry logic in the event the device loses network connectivity, and automatically batches requests to reduce network bandwidth.

```swift
func recordEvents() {
Expand Down Expand Up @@ -42,6 +42,21 @@ Events have default configuration to flush out to the network every 60 seconds.

> **Note**: If you set `autoFlushEventsInterval` to 0, you are responsible for calling `Amplify.Analytics.flushEvents()` to submit the recorded events to the backend.

## Authentication events

import native_common from "/src/fragments/lib-v1/analytics/native_common/getting-started/auth-events.mdx";

<Fragments fragments={{all: native_common}} />

```swift
func sendUserSignInEvent() {
let event = BasicAnalyticsEvent(
name: "_userauth.sign_in"
)
Amplify.Analytics.record(event: event)
}
```

## Global Properties

You can register properties which will be used across all `Amplify.Analytics.record(event:)` calls.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 **amplifyconfiguration.json** by adding the `PinpointAppId` key under `CognitoUserPool`.

```json
"CognitoUserPool": {
"Default": {
"PoolId": "<poolid>",
"AppClientId": "<appclientid>",
"Region": "<region>",
"PinpointAppId": "<pinpointappid>"
}
}
```

- Manually recording events using the `recordEvent()` API.

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.
54 changes: 54 additions & 0 deletions src/fragments/lib/analytics/android/record.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,60 @@ RxAmplify.Analytics.flushEvents();

When flushing events, a [Hub event](/lib/utilities/hub) is sent containing the events which were successfully sent to the Pinpoint service. To receive a list of these events, subscribe to the `HubChannel.ANALYTICS` channel and handle an event of the type `AnalyticsChannelEventName.FLUSH_EVENTS`.

## Authentication events

import native_common from "/src/fragments/lib-v1/analytics/native_common/getting-started/auth-events.mdx";

<Fragments fragments={{all: native_common}} />

<BlockSwitcher>
<Block name="Java">

```java
/**
* Call this method to log an authentication event to the analytics client.
*/
public void logAuthenticationEvent() {
AnalyticsEvent event = AnalyticsEvent.builder()
.name("_userauth.sign_in")
.build();
Amplify.Analytics.recordEvent(event);
}
```

</Block>
<Block name="Kotlin">

```kotlin

/**
* Call this method to log an authentication event to the analytics client.
*/
fun logAuthenticationEvent() {
val event = AnalyticsEvent.builder()
.name("_userauth.sign_in")
.build()
Amplify.Analytics.recordEvent(event)
}
```
</Block>
<Block name="RxJava">

```java

/**
* Call this method to log an authentication event to the analytics client.
*/
public void logAuthenticationEvent() {
AnalyticsEvent event = AnalyticsEvent.builder()
.name("_userauth.sign_in")
.build();
RxAmplify.Analytics.recordEvent(event);
}
```
</Block>
</BlockSwitcher>

## Global Properties

You can register global properties which will be sent along with all invocations of `Amplify.Analytics.recordEvent`.
Expand Down
15 changes: 15 additions & 0 deletions src/fragments/lib/analytics/ios/record.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ Amplify.Analytics.flushEvents()

The plugin automatically batches requests in order to reduce network bandwidth and handles the retry logic if the device loses connectivity.

## Authentication events

import native_common from "/src/fragments/lib-v1/analytics/native_common/getting-started/auth-events.mdx";

<Fragments fragments={{all: native_common}} />

```swift
func sendUserSignInEvent() {
let event = BasicAnalyticsEvent(
name: "_userauth.sign_in"
)
Amplify.Analytics.record(event: event)
}
```

## Global Properties

You can register properties which will be included across all `Amplify.Analytics.record(event:)` calls.
Expand Down