Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Jun 28, 2024

Record events

Recording Custom Events

To record custom events call the record API:

src/index.js
import { record } from 'aws-amplify/analytics';
record({
name: 'albumVisit',
});

Analytics events are buffered in memory and periodically sent to the service and not saved locally between application sessions. If the session is ended before a buffered event is sent, it will be lost. Use the flushEvents API to manually send buffered events to the service.

Record a Custom Event with Attributes

The record API lets you add additional attributes to an event. For example, to record artist information with an albumVisit event:

src/index.js
import { record } from 'aws-amplify/analytics';
record({
name: 'albumVisit',
attributes: { genre: '', artist: '' },
});

Recorded events will be buffered and periodically sent to Amazon Pinpoint.

Record Engagement Metrics

Metrics can also be added to an event:

src/index.js
import { record } from 'aws-amplify/analytics';
record({
name: 'albumVisit',
metrics: { minutesListened: 30 },
});

Metric values must be a Number type such as a float or integer.

The Amazon Pinpoint event count updates in minutes after recording your event.

However, it can take upwards of 30 minutes for the event to display in the Filter section, and for its custom attributes to appear in Amazon Pinpoint.

Flush events

The recorded events are saved in a buffer and sent to the remote server periodically. If needed, you have the option to manually clear all the events from the buffer by using the 'flushEvents' API.

src/index.js
import { flushEvents } from 'aws-amplify/analytics';
flushEvents();