Automatically track sessions
Analytics Auto Tracking helps you to automatically track user behaviors like sessions start/stop, page view change and web events like clicking or mouseover.
Session Tracking
You can track the session both in a web app or a React Native app by using Analytics. A web session can be defined in different ways. To keep it simple we define a web session as being active when the page is not hidden and inactive when the page is hidden. A session in a React Native app is active when the app is in the foreground and inactive when the app is in the background.
For example:
1import { configureAutoTrack } from 'aws-amplify/analytics';2
3configureAutoTrack({4 // REQUIRED, turn on/off the auto tracking5 enable: true,6 // REQUIRED, the event type, it's one of 'event', 'pageView' or 'session'7 type: 'session',8 // OPTIONAL, additional options for the tracked event.9 options: {10 // OPTIONAL, the attributes of the event11 attributes: {12 customizableField: 'attr'13 }14 }15});
By default, when the page/app transitions to the foreground, the Analytics module will send an event to the Amazon Pinpoint Service.
1{2 "eventType": "_session_start",3 "attributes": {4 "customizableField": "attr"5 }6}
This behavior can be disabled by calling configureAutoTrack
:
1import { configureAutoTrack } from 'aws-amplify/analytics';2
3configureAutoTrack({4 enable: false,5 type: 'session'6});