-
Notifications
You must be signed in to change notification settings - Fork 22
/
VideoAnalyticsProvider.m
293 lines (232 loc) · 11.2 KB
/
VideoAnalyticsProvider.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
* ADOBE SYSTEMS INCORPORATED
* Copyright 2015 Adobe Systems Incorporated
* All Rights Reserved.
* NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
* terms of the Adobe license agreement accompanying it. If you have received this file from a
* source other than Adobe, then your use, modification, or distribution of it requires the prior
* written permission of Adobe.
*/
#import <MediaPlayer/MediaPlayer.h>
#import "VideoAnalyticsProvider.h"
#import "VideoPlayer.h"
#import "VideoPlayerDelegate.h"
#import "Configuration.h"
#import "ADB_VHB_VideoPlayerPlugin.h"
#import "SampleAnalyticsPluginDelegate.h"
#import "ADB_VHB_VideoPlayerPluginConfig.h"
#import "SampleHeartbeatDelegate.h"
#import "SampleHeartbeatPluginDelegate.h"
#import "ADB_VHB_HeartbeatConfig.h"
#import "ADB_VHB_AdobeAnalyticsPluginConfig.h"
#import "ADB_VHB_AdobeHeartbeatPluginConfig.h"
#import "ADB_VHB_AdobeAnalyticsPlugin.h"
#import "ADB_VHB_AdobeHeartbeatPlugin.h"
#import "ADB_VHB_Heartbeat.h"
#import "ADB_VHB_AdobeHeartbeatPluginConfig.h"
#import "ADB_VHB_StandardMetadataKeys.h"
@interface VideoAnalyticsProvider ()
@property(weak, nonatomic) VideoPlayer *player;
@property(strong, nonatomic) ADB_VHB_Heartbeat *videoHeartbeat;
@property(strong, nonatomic) ADB_VHB_VideoPlayerPluginDelegate *playerDelegate;
@property(strong,nonatomic) ADB_VHB_VideoPlayerPlugin *playerPlugin;
@property(strong,nonatomic) ADB_VHB_AdobeAnalyticsPlugin *analyticsPlugin;
@property(strong,nonatomic) ADB_VHB_AdobeHeartbeatPlugin *hbPlugin;
@end
@implementation VideoAnalyticsProvider
#pragma mark Initializer & dealloc
- (instancetype)initWithPlayer:(VideoPlayer *)player {
self = [super init];
if (self)
{
if (!player)
{
[NSException raise:@"Illegal argument." format:@"Player reference cannot be nil."];
}
_player = player;
// VIDEO PLAYER PLUGIN
_playerDelegate = [[VideoPlayerDelegate alloc] initWithPlayer:player];
_playerPlugin = [[ADB_VHB_VideoPlayerPlugin alloc] initWithDelegate:_playerDelegate];
ADB_VHB_VideoPlayerPluginConfig *playerConfig = [[ADB_VHB_VideoPlayerPluginConfig alloc] init];
playerConfig.debugLogging = YES;
[_playerPlugin configure:playerConfig];
// ANALYTICS-PLUGIN
ADB_VHB_AdobeAnalyticsPluginConfig *analyticsPluginConfig = [[ADB_VHB_AdobeAnalyticsPluginConfig alloc] init];
analyticsPluginConfig.channel = HEARTBEAT_CHANNEL;
analyticsPluginConfig.debugLogging = YES;
SampleAnalyticsPluginDelegate *analyticsDelegate = [[SampleAnalyticsPluginDelegate alloc] init];
_analyticsPlugin = [[ADB_VHB_AdobeAnalyticsPlugin alloc] initWithDelegate:analyticsDelegate];
[_analyticsPlugin configure:analyticsPluginConfig];
// HEARTBEAT-PLUGIN
SampleHeartbeatPluginDelegate *hbPluginDelegate = [[SampleHeartbeatPluginDelegate alloc] init];
_hbPlugin = [[ADB_VHB_AdobeHeartbeatPlugin alloc] initWithDelegate:hbPluginDelegate];
ADB_VHB_AdobeHeartbeatPluginConfig *hbConfig = [[ADB_VHB_AdobeHeartbeatPluginConfig alloc]
initWithTrackingServer:HEARTBEAT_TRACKING_SERVER
publisher:HEARTBEAT_PUBLISHER];
hbConfig.ovp = HEARTBEAT_OVP;
hbConfig.sdk = HEARTBEAT_SDK;
hbConfig.ssl = YES;
hbConfig.debugLogging = YES;
hbConfig.quietMode = NO;
[_hbPlugin configure:hbConfig];
// PLUGINS
NSArray *plugins = [NSArray arrayWithObjects:_playerPlugin,_analyticsPlugin,_hbPlugin,nil];
// HB CORE
SampleHeartbeatDelegate *hbDelegate = [[SampleHeartbeatDelegate alloc] init];
_videoHeartbeat = [[ADB_VHB_Heartbeat alloc] initWithDelegate:hbDelegate plugins:plugins];
ADB_VHB_HeartbeatConfig *hbCoreConfig = [[ADB_VHB_HeartbeatConfig alloc] init];
hbCoreConfig.debugLogging = YES;
[_videoHeartbeat configure:hbCoreConfig];
[self setupPlayerNotifications];
}
return self;
}
- (void)dealloc {
[self destroy];
}
#pragma mark Public methods
- (void)destroy {
// Detach from the notification center.
[[NSNotificationCenter defaultCenter] removeObserver:self];
_videoHeartbeat = nil;
_playerDelegate = nil;
}
#pragma mark VideoPlayer notification handlers
- (void)onMainVideoLoaded:(NSNotification *)notification
{
NSLog (@"Player Event: VIDEO_LOAD");
NSMutableDictionary *contextData = [[NSMutableDictionary alloc] init];
// setting Standard Video Metadata
contextData[ADBVideoMetadataKeySEASON] = @"sample season";
contextData[ADBVideoMetadataKeySHOW] = @"sample show";
contextData[ADBVideoMetadataKeyEPISODE] = @"sample episode";
contextData[ADBVideoMetadataKeyASSET_ID] = @"sample asset id";
contextData[ADBVideoMetadataKeyGENRE] = @"sample genre";
contextData[ADBVideoMetadataKeyFIRST_AIR_DATE] = @"sample air date";
contextData[ADBVideoMetadataKeyFIRST_DIGITAL_DATE] = @"sample digital date";
contextData[ADBVideoMetadataKeyRATING] = @"sample rating";
contextData[ADBVideoMetadataKeyORIGINATOR] = @"sample originator";
contextData[ADBVideoMetadataKeyNETWORK] = @"sample network";
contextData[ADBVideoMetadataKeySHOW_TYPE] = @"sample show type";
contextData[ADBVideoMetadataKeyAD_LOAD] = @"sample ad load";
contextData[ADBVideoMetadataKeyMVPD] = @"sample mvpd";
contextData[ADBVideoMetadataKeyAUTHORIZED] = @"true";
contextData[ADBVideoMetadataKeyDAY_PART] = @"sample day part";
contextData[ADBVideoMetadataKeyFEED] = @"sample feed";
contextData[ADBVideoMetadataKeySTREAM_FORMAT] = @"sample format";
_analyticsPlugin.videoMetadata = contextData;
[_playerPlugin trackVideoLoad];
}
- (void)onMainVideoUnloaded:(NSNotification *)notification
{
NSLog (@"Player Event: VIDEO_UNLOAD");
[_playerPlugin trackVideoUnload];
}
- (void)onPlay:(NSNotification *)notification
{
NSLog (@"Player Event: VIDEO_PLAY");
[_playerPlugin trackPlay];
}
- (void)onStop:(NSNotification *)notification
{
NSLog (@"Player Event: VIDEO_PAUSE");
[_playerPlugin trackPause];
}
- (void)onSeekStart:(NSNotification *)notification
{
NSLog (@"Player Event: onSeekStart");
[_playerPlugin trackSeekStart];
}
- (void)onSeekComplete:(NSNotification *)notification
{
NSLog (@"Player Event: onSeekComplete");
[_playerPlugin trackSeekComplete];
}
- (void)onComplete:(NSNotification *)notification
{
NSLog (@"Player Event: onComplete");
void (^trackCompleteHandler)(void) = ^ {
NSLog (@"The completion of the content has been tracked.");
};
[_playerPlugin trackComplete:trackCompleteHandler];
}
- (void)onChapterStart:(NSNotification *)notification
{
NSLog (@"Player Event: onChapterStart");
NSMutableDictionary *chapterDictionary = [[NSMutableDictionary alloc] init];
[chapterDictionary setObject:@"Sample segment type" forKey:@"segmentType"];
_analyticsPlugin.chapterMetadata = chapterDictionary;
[_playerPlugin trackChapterStart];
}
- (void)onChapterComplete:(NSNotification *)notification
{
NSLog (@"Player Event: onChapterComplete");
[_playerPlugin trackChapterComplete];
}
- (void)onAdStart:(NSNotification *)notification
{
NSLog (@"Player Event: onAdStart");
NSMutableDictionary *contextData = [[NSMutableDictionary alloc] init];
// setting Standard Ad Metadata
contextData[ADBAdMetadataKeyADVERTISER] = @"sample advertiser";
contextData[ADBAdMetadataKeyCAMPAIGN_ID] = @"sample campaign";
contextData[ADBAdMetadataKeyCREATIVE_ID] = @"sample creative";
contextData[ADBAdMetadataKeyCREATIVE_URL] = @"sample url";
contextData[ADBAdMetadataKeySITE_ID] = @"sample site";
contextData[ADBAdMetadataKeyPLACEMENT_ID] = @"sample placement";
[_analyticsPlugin setAdMetadata:contextData];
[_playerPlugin trackAdStart];
}
- (void)onAdComplete:(NSNotification *)notification
{
NSLog (@"Player Event: onAdComplete");
[_playerPlugin trackAdComplete];
}
#pragma mark - Private helper methods
- (void)setupPlayerNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onMainVideoLoaded:)
name:PLAYER_EVENT_VIDEO_LOAD
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onMainVideoUnloaded:)
name:PLAYER_EVENT_VIDEO_UNLOAD
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onPlay:)
name:PLAYER_EVENT_PLAY
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onStop:)
name:PLAYER_EVENT_PAUSE
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onSeekStart:)
name:PLAYER_EVENT_SEEK_START
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onSeekComplete:)
name:PLAYER_EVENT_SEEK_COMPLETE
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onComplete:)
name:PLAYER_EVENT_COMPLETE
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onChapterStart:)
name:PLAYER_EVENT_CHAPTER_START
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onChapterComplete:)
name:PLAYER_EVENT_CHAPTER_COMPLETE
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onAdStart:)
name:PLAYER_EVENT_AD_START
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onAdComplete:)
name:PLAYER_EVENT_AD_COMPLETE
object:self.player];
}
@end