Track chapters and segments on iOS

IMPORTANT

The following instructions provide guidance for implementation using 2.x SDKs. If you are implementing a 1.x version of the SDK, you can download the Developers Guide here: Download SDKs.

  1. Identify when the chapter start event occurs and create the ChapterObject instance by using the chapter information.

    ChapterObject chapter tracking reference:

    NOTE

    These variables are only required if you are planning to track chapters.

    Variable Name Description Required
    name Chapter name Yes
    position Chapter position Yes
    length Chapter length Yes
    startTime Chapter start time Yes

    Chapter object:

    id chapterObject =  
      [ADBMediaHeartbeat createChapterObjectWithName:[CHAPTER_NAME] 
                         position:[POSITION] 
                         length:[LENGTH] 
                         startTime:[START_TIME]];
    
  2. If you include custom metadata for the chapter, create the context data variables for the metadata:

    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"];
    
  3. To begin tracking the chapter playback, call the ChapterStart event in the MediaHeartbeat instance:

    - (void)onChapterStart:(NSNotification *)notification { 
        [_mediaHeartbeat trackEvent:ADBMediaHeartbeatEventChapterStart  
                         mediaObject:chapterObject     
                         data:chapterDictionary]; 
    }
    
  4. When playback reaches the chapter end boundary, as defined by your custom code, call the ChapterComplete event in the MediaHeartbeat instance:

    - (void)onChapterComplete:(NSNotification *)notification { 
        [_mediaHeartbeat trackEvent:ADBMediaHeartbeatEventChapterComplete  
                         mediaObject:nil  
                         data:nil]; 
    }
    
  5. 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:

    - (void)onChapterSkip:(NSNotification *)notification { 
        [_mediaHeartbeat trackEvent:ADBMediaHeartbeatEventChapterSkip  
                         mediaObject:nil  
                         data:nil]; 
    }
    
  6. If there are any additional chapters, repeat steps 1 through 5.

On this page

Adobe Summit Banner

A virtual event April 27-28.

Expand your skills and get inspired.

Register for free
Adobe Summit Banner

A virtual event April 27-28.

Expand your skills and get inspired.

Register for free
Adobe Maker Awards Banner

Time to shine!

Apply now for the 2021 Adobe Experience Maker Awards.

Apply now
Adobe Maker Awards Banner

Time to shine!

Apply now for the 2021 Adobe Experience Maker Awards.

Apply now