Page updated Nov 9, 2023

Record events

Recording Custom Events

To record custom events call the record API:

import { record } from 'aws-amplify/analytics'; record({ event: { name: 'albumVisit' } });
1import { record } from 'aws-amplify/analytics';
2
3record({
4 event: {
5 name: 'albumVisit'
6 }
7});

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:

import { record } from 'aws-amplify/analytics'; record({ event: { name: 'albumVisit', attributes: { genre: '', artist: '' } } });
1import { record } from 'aws-amplify/analytics';
2
3record({
4 event: {
5 name: 'albumVisit',
6 attributes: { genre: '', artist: '' }
7 }
8});

Recorded events will be buffered and periodically sent to Pinpoint.

Record Engagement Metrics

Metrics can also be added to an event:

import { record } from 'aws-amplify/analytics'; record({ event: { name: 'albumVisit', metrics: { minutesListened: 30 } } });
1import { record } from 'aws-amplify/analytics';
2
3record({
4 event: {
5 name: 'albumVisit',
6 metrics: { minutesListened: 30 }
7 }
8});

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

The AWS 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 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.

import { flushEvents } from 'aws-amplify/analytics'; flushEvents();
1import { flushEvents } from 'aws-amplify/analytics';
2
3flushEvents();