This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added slot-info to some events payload * Some refinements on the metrics * Removed console.logs * Some more work on slot-events * Moved metrics logic from n-ui to o-ads * Renamed slot events * Added missing "name" attribute to slot events payload * Fixed linting warnings * Made code more robust * Fixed broken unit tests * Added unit tests for changes in broadcast * Added missing unit tests * Added some more unit tests * Added a couple of istanbul ignores * Fixed some indentation * Added some more unit tests * Improved a test * Temporarily remove samsung galaxy from e2e tests * Relaxed condition for a targeting API response * Allow bigger bundle size * Update src/js/ad-servers/gpt.js Accept comma separators for multiple pos values * Update src/js/ad-servers/gpt.js Use `join` to join array instead of `toString` for consistency * Update src/js/ad-servers/gpt.js Fixed indentation * Increase bundle size * Fix linting problem
- Loading branch information
1 parent
b820c89
commit 7719110
Showing
22 changed files
with
539 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
function getMarksForEvents(events, suffix) { | ||
const markNames = events.map( eventName => 'oAds.' + eventName + suffix ); | ||
const performance = window.LUX || window.performance || window.msPerformance || window.webkitPerformance || window.mozPerformance; | ||
if (!performance || !performance.getEntriesByName) { | ||
/* istanbul ignore next */ | ||
return {}; | ||
} | ||
|
||
const marks = {}; | ||
markNames.forEach(function(mName) { | ||
const pMarks = performance.getEntriesByName(mName); | ||
const markName = mName.replace('oAds.', '').replace(suffix, ''); | ||
if (pMarks && pMarks.length) { | ||
// We don't need sub-millisecond precision | ||
marks[markName] = Math.round(pMarks[0].startTime); | ||
} | ||
}); | ||
return marks; | ||
} | ||
|
||
export function setupMetrics(definitions, callback) { | ||
if (!Array.isArray(definitions)) { | ||
this.log.warn('Metrics definitions should be an array. o-Ads will not record any metrics.'); | ||
return; | ||
} | ||
|
||
definitions.forEach( function(eDef) { | ||
const triggers = Array.isArray(eDef.triggers) ? eDef.triggers : []; | ||
triggers.forEach(function(trigger) { | ||
sendMetricsOnEvent('oAds.' + trigger, eDef, callback); | ||
}); | ||
}); | ||
} | ||
|
||
function sendMetricsOnEvent(eventName, eMarkMap, callback) { | ||
document.addEventListener(eventName, function listenOnInitialised(event) { | ||
sendMetrics(eMarkMap, event.detail, callback); | ||
if (!eMarkMap.multiple) { | ||
document.removeEventListener(eventName, listenOnInitialised); | ||
} | ||
}); | ||
} | ||
|
||
function sendMetrics(eMarkMap, eventDetails, callback) { | ||
let suffix = ''; | ||
if (eventDetails && 'pos' in eventDetails && 'name' in eventDetails) { | ||
suffix = '__' + [eventDetails.pos, eventDetails.name, eventDetails.size].join('__'); | ||
} | ||
|
||
const marks = getMarksForEvents(eMarkMap.marks, suffix); | ||
|
||
const eventPayload = { | ||
category: 'ads', | ||
action: eMarkMap.spoorAction, | ||
timings: { marks: marks } | ||
}; | ||
|
||
if (eventDetails && 'pos' in eventDetails) { | ||
eventPayload.creative = { | ||
name: eventDetails.name, | ||
pos: eventDetails.pos, | ||
size: eventDetails.size && eventDetails.size.toString() | ||
}; | ||
} | ||
|
||
callback(eventPayload); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.