Skip to content

Instantly share code, notes, and snippets.

@giannif
Last active December 10, 2015 18:38
Show Gist options
  • Save giannif/4475490 to your computer and use it in GitHub Desktop.
Save giannif/4475490 to your computer and use it in GitHub Desktop.
BRBPL-3391 Listen for the player `performance` event, and report to omniture. Requires embed api v2.5.0.
// make sure this is defined on window.
var _gaq = window._gaq = window._gaq || [];
// set the account here. UA-37497376-1 is the one tied to gianni.ferullo@mtvn.com.
_gaq.push(['_setAccount', 'UA-37497376-1']);
// callback for 'performance' event.
function onPerformanceResults(event){
// see https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingTiming
// event.data is the performance results, loop through them:
for(var prop in event.data){
// we're using event.target.config.uri as the label. anything can be used here.
// the last arg is the sample rate, you'll want to choose something lower than 100.
_gaq.push(["_trackTiming", "player_performance", prop, event.data[prop], event.target.config.uri, 100]);
}
}
// pass the callback to a player. This assumes you have a player created.
// IMPORTANT: the player must have a config property peformance = true. e.g. {width:640,height:340,performance:true}
// There is a decoupled way to do this, see: https://github.com/mtvn-player/embed-api#a4-3
player.on("performance",onPerformanceResults);
// load Google Analytics asynchronously - see https://developers.google.com/analytics/devguides/collection/gajs/.
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
@giannif
Copy link
Author

giannif commented Jan 7, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment