Track chapters and segments on Android track-chapters-and-segments-on-android
The following instructions provide guidance for implementation using 2.x SDKs.
Implement chapter tracking
-
Identify when the chapter start event occurs and create the
ChapterObject
instance by using the chapter information.ChapterObject
chapter tracking reference:note note NOTE These variables are only required if you are planning to track chapters. table 0-row-3 1-row-3 2-row-3 3-row-3 4-row-3 3-align-center 7-align-center 11-align-center 15-align-center 19-align-center Variable Name Description Required name
Chapter name Yes position
Chapter position Yes length
Chapter length Yes startTime
Chapter start time Yes Chapter object:
code language-java MediaObject chapterDataInfo = MediaHeartbeat.createChapterObject(<CHAPTER_NAME>, <POSITION>, <LENGTH>, <START_TIME>);
-
If you include custom metadata for the chapter, create the context data variables for the metadata:
code language-java HashMap<String, String> chapterMetadata = new HashMap<String,String>(); chapterMetadata.put("segmentType", "Sample Segment Type"); chapterMetadata.put("segmentName", "Sample Segment Name"); chapterMetadata.put("segmentInfo", "Sample Segment Info");
-
To begin tracking the chapter playback, call the
ChapterStart
event in theMediaHeartbeat
instance:code language-java public void onChapterStart(Observable observable, Object data) { _heartbeat.trackEvent(MediaHeartbeat.Event.ChapterStart, chapterDataInfo, chapterMetadata); }
-
When playback reaches the chapter end boundary, as defined by your custom code, call the
ChapterComplete
event in theMediaHeartbeat
instance:code language-java public void onChapterComplete(Observable observable, Object data) { _heartbeat.trackEvent(MediaHeartbeat.Event.ChapterComplete, null, null); }
-
If chapter playback did not complete because the user chose to skip the chapter (for example, if the user seeks out of the chapter boundary), call the
ChapterSkip
event in the MediaHeartbeat instance:code language-java public void onChapterSkip(Observable observable, Object data) { _heartbeat.trackEvent(MediaHeartbeat.Event.ChapterSkip, null, null); }
-
If there are any additional chapters, repeat steps 1 through 5.