Track chapters and segments on iOS track-chapters-and-segments-on-ios
The following instructions provide guidance for implementation using 2.x SDKs.
-
Identify when the chapter start event occurs and create the
ChapterObjectinstance by using the chapter information.ChapterObjectchapter 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 nameChapter name Yes positionChapter position Yes lengthChapter length Yes startTimeChapter start time Yes Chapter object:
code language-none id chapterObject = [ADBMediaHeartbeat createChapterObjectWithName:[CHAPTER_NAME] position:[POSITION] length:[LENGTH] startTime:[START_TIME]]; -
If you include custom metadata for the chapter, create the context data variables for the metadata:
code language-none NSMutableDictionary *chapterDictionary = [[NSMutableDictionary alloc] init]; [chapterDictionary setObject:@"Sample segment type" forKey:@"segmentType"]; [chapterDictionary setObject:@"Sample segment name" forKey:@"segmentName"]; [chapterDictionary setObject:@"Sample segment info" forKey:@"segmentInfo"]; -
To begin tracking the chapter playback, call the
ChapterStartevent in theMediaHeartbeatinstance:code language-none - (void)onChapterStart:(NSNotification *)notification { [_mediaHeartbeat trackEvent:ADBMediaHeartbeatEventChapterStart mediaObject:chapterObject data:chapterDictionary]; } -
When playback reaches the chapter end boundary, as defined by your custom code, call the
ChapterCompleteevent in theMediaHeartbeatinstance:code language-none - (void)onChapterComplete:(NSNotification *)notification { [_mediaHeartbeat trackEvent:ADBMediaHeartbeatEventChapterComplete mediaObject:nil data:nil]; } -
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
ChapterSkipevent in the MediaHeartbeat instance:code language-none - (void)onChapterSkip:(NSNotification *)notification { [_mediaHeartbeat trackEvent:ADBMediaHeartbeatEventChapterSkip mediaObject:nil data:nil]; } -
If there are any additional chapters, repeat steps 1 through 5.