Skip to content

Commit

Permalink
fixes analytics test file
Browse files Browse the repository at this point in the history
* use MWEMBED_VERSION instead of kaltura loader ( not present on
iframe side )
* output version in mwEmbedStartup.php
  • Loading branch information
mdale committed Jun 20, 2012
1 parent 0a5566f commit 112253a
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 36 deletions.
4 changes: 2 additions & 2 deletions kWidget/kWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ var kWidget = {
}

// Also append the script version to purge the cdn cache for iframe:
iframeRequest += '&urid=' + KALTURA_LOADER_VERSION;
iframeRequest += '&urid=' + MWEMBED_VERSION;
return iframeRequest;
},
getIframeUrl: function(){
Expand Down Expand Up @@ -548,7 +548,7 @@ var kWidget = {
}

// Also append the script version to purge the cdn cache for iframe:
iframeSrc += '&urid=' + KALTURA_LOADER_VERSION;
iframeSrc += '&urid=' + MWEMBED_VERSION;

var targetNode = document.getElementById( targetId );
var parentNode = targetNode.parentNode;
Expand Down
2 changes: 1 addition & 1 deletion kWidget/mwEmbedLoader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The version of this script
var logIfInIframe = ( typeof preMwEmbedConfig != 'undefined' && preMwEmbedConfig['EmbedPlayer.IsIframeServer'] ) ? ' ( iframe ) ': '';
kWidget.log( 'Kaltura HTML5 Version: ' + KALTURA_LOADER_VERSION + logIfInIframe );
kWidget.log( 'Kaltura HTML5 Version: ' + MWEMBED_VERSION + logIfInIframe );

// Define mw ( if not already set )
if( !window['mw'] ) {
Expand Down
3 changes: 2 additions & 1 deletion modules/KalturaSupport/KalturaSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
/* uiConf based plugins */
"statisticsPlugin"=> array(
'scripts' => "resources/uiConfComponents/statisticsPlugin.js",
'dependencies' => array( 'mw.KAnalytics' )
'dependencies' => array( 'mw.KAnalytics' ),
'kalturaPluginName' => 'statistics'
),
"vastPlugin"=> array(
'scripts' => "resources/uiConfComponents/vastPlugin.js",
Expand Down
15 changes: 12 additions & 3 deletions modules/KalturaSupport/resources/mw.KAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mw.addKAnalytics = function( embedPlayer ) {
mw.KAnalytics.prototype = {

// The version of html5 player
version : window['KALTURA_LOADER_VERSION'],
version : window['MWEMBED_VERSION'],

// Local reference to embedPlayer
embedPlayer: null,
Expand Down Expand Up @@ -111,7 +111,7 @@ mw.KAnalytics.prototype = {
},
doSendAnalyticsEvent: function( ks, KalturaStatsEventKey ){
var _this = this;

mw.log("KAnalytics :: doSendAnalyticsEvent > " + KalturaStatsEventKey );
// Kalutra analytics does not collect info for ads:
if( this.embedPlayer.evaluate('{sequenceProxy.isInSequence}') ){
return ;
Expand Down Expand Up @@ -169,7 +169,7 @@ mw.KAnalytics.prototype = {
}
}

// Add referer parameter
// Add referrer parameter
eventSet[ 'referrer' ] = encodeURIComponent( mw.getConfig('EmbedPlayer.IframeParentUrl') );

// Add in base service and action calls:
Expand All @@ -181,6 +181,15 @@ mw.KAnalytics.prototype = {

// Send events for this player:
$( this.embedPlayer ).trigger( 'KalturaSendAnalyticEvent', [ KalturaStatsEventKey, eventSet ] );

// Also trigger the event on the parent document ( for audits and alternate statistic packages )
if( window.parent['kalturaSendAnalyticEvent'] ){
try{
window.parent.kalturaSendAnalyticEvent( KalturaStatsEventKey, eventSet );
} catch( e ){

}
}

// Do the api request:
this.kClient.doRequest( eventRequest );
Expand Down
2 changes: 1 addition & 1 deletion modules/KalturaSupport/resources/mw.KApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mw.KApi = function( partner_id ){
mw.KApi.prototype = {
baseParam: {
'apiVersion' : '3.1',
'clientTag' : 'html5:v' + window[ 'KALTURA_LOADER_VERSION' ],
'clientTag' : 'html5:v' + window[ 'MWEMBED_VERSION' ],
'expiry' : '86400',
'format' : 9, // 9 = JSONP format
'ignoreNull' : 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
* mw.KAnalytics
*/
( function( mw, $ ) { "use strict";
$( mw ).bind( 'EmbedPlayerNewPlayer', function( event, embedPlayer ){
$( embedPlayer ).bind( 'KalturaSupport_CheckUiConf', function( event, $uiConf, callback ){
// Check if plugin exists
if( embedPlayer.isPluginEnabled( 'statistics' ) ) {
mw.addKAnalytics( embedPlayer );
}
callback();
});

mw.addKalturaPlugin( "statistics", function( embedPlayer, callback){
mw.addKAnalytics( embedPlayer );
callback();
});

})( window.mw, window.jQuery );
window['statisticsPlugin'] = true;
34 changes: 16 additions & 18 deletions modules/KalturaSupport/tests/KalturaAnalytics.qunit.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Fall forward html5</title>
<title>Analytics test </title>

<script type="text/javascript" src="../../../tests/qunit/qunit-bootstrap.js"></script>
<script type="text/javascript" src="../../../mwEmbedLoader.php?debug=true"></script>
Expand All @@ -10,15 +10,15 @@
// Name this module
module( "Kaltura analytics" );

asyncTest("Beacon includes required properties", function(){
window[ 'sendKalturaSendAnalyticEvent' ] = function( aName, aEvent ){
if( aName != 'MEDIA_LOADED' ){
// Only check for 'MEDIA_LOADED' for now
return ;
}
window[ 'sendKalturaSendAnalyticEvent' ] = function( aName, aEvent ){
if( aName != 'MEDIA_LOADED' ){
// Only check for 'MEDIA_LOADED' for now
return ;
}
asyncTest("Beacon includes required properties", function(){
equal( aName, 'MEDIA_LOADED', "Event name is MEDIA_LOADED");

equal( aEvent['clientVer'], window['KALTURA_LOADER_VERSION'], ' Library version match');
equal( aEvent['clientVer'], window['MWEMBED_VERSION'], ' Library version match');

equal( aEvent['currentPoint'], 0, 'Cuepoint is zero')

Expand Down Expand Up @@ -51,30 +51,28 @@
equal( aEvent[ 'userId'], 'customUid', "Set Custom user id");

start();
};
})
});
};
}
</script>
<!-- qunit-kaltura must come after qunit-bootstrap.js and after mwEmbedLoader.php and after any jsCallbackReady stuff-->
<script type="text/javascript" src="resources/qunit-kaltura-bootstrap.js"></script>

<script type="text/javascript">
$( document ).bind( 'KalturaSendAnalyticEvent', function(event, analyticName, analyticValue){
window['kalturaSendAnalyticEvent'] = function( analyticName, analyticValue){
$('#analyticsLog').append( analyticName + "\n");
setTimeout(function(){
if( window['sendKalturaSendAnalyticEvent'] ){
sendKalturaSendAnalyticEvent( analyticName, analyticValue );
}
},100);
});
if( window['sendKalturaSendAnalyticEvent'] ){
sendKalturaSendAnalyticEvent( analyticName, analyticValue );
}
};
// non-jquery display of events:
if( window.QUnit ){
$(document).ready(function(){ $('#analyticsContainer').hide() });
}
</script>
</head>
<body>
<h2> Fall forward: ( kaltura embed code on iPad / iPhone ) + analytics </h2>
<h2> Kaltura analytics </h2>
<a href="?forceMobileHTML5"> Force Mobile Safari</a> for testing with desktop chrome and safari.

<br />
Expand Down
2 changes: 1 addition & 1 deletion mwEmbedLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$loaderJs = "window['SCRIPT_LOADER_URL'] = '". addslashes( $wgResourceLoaderUrl ) . "';\n";

// Add the library version:
$loaderJs .= "window['KALTURA_LOADER_VERSION'] = '$wgMwEmbedVersion';\n";
$loaderJs .= "window['MWEMBED_VERSION'] = '$wgMwEmbedVersion';\n";

// Get resource ( kWidgetLoader.js )
$loaderJs .= file_get_contents( 'kWidget/kWidget.js' );
Expand Down
3 changes: 3 additions & 0 deletions mwEmbedStartup.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
print "if( console && console.log ){ console.log( 'Error can't find load.php' ) }";
}

// Output MWEMBED_VERSION global:
echo "window['MWEMBED_VERSION'] = '$wgMwEmbedVersion';\n";

// Bootstrap some js code to make the "loader" work in stand alone mode
// not need when iframe includes starup and sets iframeStartup flag
if( !isset( $_GET[ 'iframeStartup' ] ) ){
Expand Down

0 comments on commit 112253a

Please sign in to comment.