@@ -16,7 +16,9 @@ var NielsenDCR = (module.exports = integration('Nielsen DCR')
16
16
. option ( 'appId' , '' )
17
17
. option ( 'instanceName' , '' ) // the snippet lets you override the instance so make sure you don't have any global window props w same value as this setting unless you are intentionally doing that.
18
18
. option ( 'nolDevDebug' , false )
19
- . option ( 'assetIdPropertyName' , 'asset_id' )
19
+ . option ( 'assetIdPropertyName' , '' ) // deprecated
20
+ . option ( 'contentAssetIdPropertyName' , '' )
21
+ . option ( 'adAssetIdPropertyName' , '' )
20
22
. option ( 'subbrandPropertyName' , '' )
21
23
. option ( 'clientIdPropertyName' , '' )
22
24
. option ( 'contentLengthPropertyName' , 'total_length' )
@@ -114,10 +116,13 @@ NielsenDCR.prototype.page = function(page) {
114
116
115
117
NielsenDCR . prototype . heartbeat = function ( assetId , position , options ) {
116
118
var self = this ;
117
- var newPosition ;
119
+ var newPosition = position ;
118
120
var opts = options || { } ;
121
+ // if position is not sent as a string
119
122
try {
120
- if ( typeof position !== 'number' ) newPosition = parseInt ( position , 10 ) ; // in case it is sent as a string
123
+ if ( typeof position !== 'number' ) {
124
+ newPosition = parseInt ( position , 10 ) ;
125
+ } // in case it is sent as a string
121
126
} catch ( e ) {
122
127
// if we can't parse position into an Int for some reason, early return
123
128
// to prevent internal errors every second
@@ -159,12 +164,18 @@ NielsenDCR.prototype.heartbeat = function(assetId, position, options) {
159
164
160
165
NielsenDCR . prototype . getContentMetadata = function ( track , type ) {
161
166
var properties = 'properties.' ;
162
- if ( type && type === 'preroll' ) properties = 'properties.content.' ;
167
+ var assetIdProp = 'asset_id' ;
168
+ if ( type ) {
169
+ if ( type === 'preroll' ) properties = 'properties.content.' ;
170
+ if ( type === 'video' ) assetIdProp = 'content_asset_id' ;
171
+ }
163
172
164
173
var integrationOpts = track . options ( this . name ) ;
165
174
var contentMetadata = {
166
175
type : 'content' ,
167
- assetid : getAssetId ( track , this . options . assetIdPropertyName , type ) ,
176
+ assetid : this . options . contentAssetIdPropertyName
177
+ ? track . proxy ( properties + this . options . contentAssetIdPropertyName )
178
+ : track . proxy ( properties + assetIdProp ) ,
168
179
program : track . proxy ( properties + 'program' ) ,
169
180
title : track . proxy ( properties + 'title' ) ,
170
181
isfullepisode : track . proxy ( properties + 'full_episode' ) ? 'y' : 'n' ,
@@ -214,15 +225,15 @@ NielsenDCR.prototype.getContentMetadata = function(track, type) {
214
225
215
226
NielsenDCR . prototype . getAdMetadata = function ( track ) {
216
227
var type = track . proxy ( 'properties.type' ) ;
217
- var adMetadata ;
218
- var assetId = getAssetId ( track , this . options . assetIdPropertyName ) ;
219
-
220
228
if ( typeof type === 'string' ) type = type . replace ( '-' , '' ) ;
221
229
222
- adMetadata = {
223
- assetid : track . proxy ( 'ad_asset_id' ) || assetId ,
230
+ var adMetadata = {
231
+ assetid : this . options . adAssetIdPropertyName
232
+ ? track . proxy ( 'properties.' + this . options . adAssetIdPropertyName )
233
+ : track . proxy ( 'properties.ad_asset_id' ) ,
224
234
type : type
225
235
} ;
236
+
226
237
return adMetadata ;
227
238
} ;
228
239
@@ -260,7 +271,9 @@ NielsenDCR.prototype.videoContentStarted = function(track) {
260
271
NielsenDCR . prototype . videoContentPlaying = function ( track ) {
261
272
clearInterval ( this . heartbeatId ) ;
262
273
263
- var assetId = getAssetId ( track , this . options . assetIdPropertyName ) ;
274
+ var assetId = this . options . contentAssetIdPropertyName
275
+ ? track . proxy ( 'properties.' + this . options . contentAssetIdPropertyName )
276
+ : track . proxy ( 'properties.asset_id' ) ;
264
277
var position = track . proxy ( 'properties.position' ) ;
265
278
var livestream = track . proxy ( 'properties.livestream' ) ;
266
279
@@ -300,11 +313,9 @@ NielsenDCR.prototype.videoContentCompleted = function(track) {
300
313
NielsenDCR . prototype . videoAdStarted = function ( track ) {
301
314
clearInterval ( this . heartbeatId ) ;
302
315
303
- var adAssetId = getAssetId (
304
- track ,
305
- this . options . assetIdPropertyName ,
306
- 'adMetadata'
307
- ) ;
316
+ var adAssetId = this . options . adAssetIdPropertyName
317
+ ? track . proxy ( 'properties.' + this . options . adAssetIdPropertyName )
318
+ : track . proxy ( 'properties.asset_id' ) ;
308
319
var position = track . proxy ( 'properties.position' ) ;
309
320
var type = track . proxy ( 'properties.type' ) ;
310
321
if ( typeof type === 'string' ) type = type . replace ( '-' , '' ) ;
@@ -332,7 +343,9 @@ NielsenDCR.prototype.videoAdStarted = function(track) {
332
343
NielsenDCR . prototype . videoAdPlaying = function ( track ) {
333
344
clearInterval ( this . heartbeatId ) ;
334
345
335
- var assetId = getAssetId ( track , this . options . assetIdPropertyName ) ;
346
+ var assetId = this . options . adAssetIdPropertyName
347
+ ? track . proxy ( 'properties.' + this . options . adAssetIdPropertyName )
348
+ : track . proxy ( 'properties.asset_id' ) ;
336
349
var position = track . proxy ( 'properties.position' ) ;
337
350
this . heartbeat ( assetId , position , { type : 'ad' } ) ;
338
351
} ;
@@ -362,7 +375,9 @@ NielsenDCR.prototype.videoPlaybackInterrupted = function(track) {
362
375
363
376
// if properly implemented, the point in which the playback is resumed
364
377
// you should _only_ be sending the asset_id of whatever you are pausing in: content or ad
365
- var adAssetId = track . proxy ( 'properties.ad_asset_id' ) ;
378
+ var adAssetId = this . options . adAssetIdPropertyName
379
+ ? track . proxy ( 'properties.' + this . options . adAssetIdPropertyName )
380
+ : track . proxy ( 'properties.ad_asset_id' ) ;
366
381
// if playback was interrupted during an ad, we only call `stop`
367
382
// if interrupted during content play, we call both `end` and `stop`
368
383
var position = track . proxy ( 'properties.position' ) ;
@@ -381,8 +396,12 @@ NielsenDCR.prototype.videoPlaybackInterrupted = function(track) {
381
396
NielsenDCR . prototype . videoPlaybackSeekCompleted = function ( track ) {
382
397
clearInterval ( this . heartbeatId ) ;
383
398
384
- var contentAssetId = track . proxy ( 'properties.content_asset_id' ) ;
385
- var adAssetId = track . proxy ( 'properties.ad_asset_id' ) ;
399
+ var contentAssetId = this . options . contentAssetIdPropertyName
400
+ ? track . proxy ( 'properties.' + this . options . contentAssetIdPropertyName )
401
+ : track . proxy ( 'properties.content_asset_id' ) ;
402
+ var adAssetId = this . options . adAssetIdPropertyName
403
+ ? track . proxy ( 'properties.' + this . options . adAssetIdPropertyName )
404
+ : track . proxy ( 'properties.ad_asset_id' ) ;
386
405
var position = track . proxy ( 'properties.position' ) ;
387
406
var livestream = track . proxy ( 'properties.livestream' ) ;
388
407
// if properly implemented, the point in which the playback is resumed
@@ -394,7 +413,10 @@ NielsenDCR.prototype.videoPlaybackSeekCompleted = function(track) {
394
413
if ( type === 'ad' ) {
395
414
this . _client . ggPM ( 'loadMetadata' , this . getAdMetadata ( track ) ) ;
396
415
} else if ( type === 'content' ) {
397
- this . _client . ggPM ( 'loadMetadata' , this . getContentMetadata ( track ) ) ;
416
+ this . _client . ggPM (
417
+ 'loadMetadata' ,
418
+ this . getContentMetadata ( track , 'video' )
419
+ ) ;
398
420
}
399
421
}
400
422
@@ -426,8 +448,12 @@ NielsenDCR.prototype.videoPlaybackPaused = function(track) {
426
448
NielsenDCR . prototype . videoPlaybackResumed = function ( track ) {
427
449
clearInterval ( this . heartbeatId ) ;
428
450
429
- var contentAssetId = track . proxy ( 'properties.content_asset_id' ) ;
430
- var adAssetId = track . proxy ( 'properties.ad_asset_id' ) ;
451
+ var contentAssetId = this . options . contentAssetIdPropertyName
452
+ ? track . proxy ( 'properties.' + this . options . contentAssetIdPropertyName )
453
+ : track . proxy ( 'properties.content_asset_id' ) ;
454
+ var adAssetId = this . options . adAssetIdPropertyName
455
+ ? track . proxy ( 'properties.' + this . options . adAssetIdPropertyName )
456
+ : track . proxy ( 'properties.ad_asset_id' ) ;
431
457
var position = track . proxy ( 'properties.position' ) ;
432
458
// if properly implemented, the point in which the playback is resumed
433
459
// you should _only_ be sending the asset_id of whatever you are resuming in: content or ad
@@ -438,7 +464,10 @@ NielsenDCR.prototype.videoPlaybackResumed = function(track) {
438
464
if ( type === 'ad' ) {
439
465
this . _client . ggPM ( 'loadMetadata' , this . getAdMetadata ( track ) ) ;
440
466
} else if ( type === 'content' ) {
441
- this . _client . ggPM ( 'loadMetadata' , this . getContentMetadata ( track ) ) ;
467
+ this . _client . ggPM (
468
+ 'loadMetadata' ,
469
+ this . getContentMetadata ( track , 'video' )
470
+ ) ;
442
471
}
443
472
}
444
473
@@ -468,27 +497,3 @@ NielsenDCR.prototype.videoPlaybackCompleted = function(track) {
468
497
this . currentAssetId = null ;
469
498
this . heartbeatId = null ;
470
499
} ;
471
-
472
- /**
473
- * Get Asset ID
474
- *
475
- * @param {Track } track
476
- * @return {string }
477
- * @api private
478
- */
479
-
480
- function getAssetId ( track , customAssetId , type ) {
481
- var assetIdValue ;
482
- var properties = 'properties.' ;
483
- if ( type === 'preroll' ) {
484
- var assetIdKey = 'asset_id' ;
485
- if ( customAssetId !== 'asset_id' ) assetIdKey = customAssetId ;
486
- properties = 'properties.content.' ;
487
- assetIdValue = track . proxy ( properties + assetIdKey ) ;
488
- } else if ( customAssetId !== 'asset_id' && type !== 'adMetadata' ) {
489
- assetIdValue = track . proxy ( properties + customAssetId ) ;
490
- } else {
491
- assetIdValue = track . proxy ( properties + 'asset_id' ) ;
492
- }
493
- return assetIdValue ;
494
- }
0 commit comments