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',});
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.
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();