Commit 9f6b95b7 by Sean Lip

Add the exploration version to the data payload of each analytics event.

parent cd5479ee
......@@ -19,7 +19,7 @@
import pkg_resources
from xblock.core import XBlock
from xblock.fields import Scope, Integer, String
from xblock.fields import Scope, String
from xblock.fragment import Fragment
......@@ -83,6 +83,7 @@ class OppiaXBlock(XBlock):
"""Called when an exploration has loaded."""
self._log(self._EVENT_NAME_EXPLORATION_LOADED, {
'exploration_id': self.oppiaid,
'exploration_version': data['explorationVersion'],
})
@XBlock.json_handler
......@@ -92,13 +93,15 @@ class OppiaXBlock(XBlock):
'exploration_id': self.oppiaid,
'old_state_name': data['oldStateName'],
'new_state_name': data['newStateName'],
'exploration_version': data['explorationVersion'],
})
@XBlock.json_handler
def on_exploration_completed(self, data, suffix=''):
"""Called when the exploration has been completed."""
self._log(self._EVENT_NAME_EXPLORATION_COMPLETED, {
'exploration_id': self.oppiaid
'exploration_id': self.oppiaid,
'exploration_version': data['explorationVersion'],
})
def studio_view(self, context):
......
......@@ -25,32 +25,39 @@ function OppiaXBlock(runtime, element) {
element, 'on_exploration_completed');
$(function ($) {
window.OPPIA_PLAYER.onExplorationLoadedPostHook = function(iframeNode) {
window.OPPIA_PLAYER.onExplorationLoadedPostHook = function(
iframeNode, explorationVersion) {
$.ajax({
type: "POST",
url: onLoadHandlerUrl,
data: JSON.stringify({})
data: JSON.stringify({
explorationVersion: explorationVersion
})
});
};
window.OPPIA_PLAYER.onStateTransitionPostHook = function(
iframeNode, oldStateName, jsonAnswer, newStateName) {
iframeNode, oldStateName, jsonAnswer, newStateName, explorationVersion) {
$.ajax({
type: "POST",
url: onStateTransitionUrl,
data: JSON.stringify({
oldStateName: oldStateName,
jsonAnswer: jsonAnswer,
newStateName: newStateName
newStateName: newStateName,
explorationVersion: explorationVersion
})
});
};
window.OPPIA_PLAYER.onExplorationCompletedPostHook = function(iframeNode) {
window.OPPIA_PLAYER.onExplorationCompletedPostHook = function(
iframeNode, explorationVersion) {
$.ajax({
type: "POST",
url: onCompleteHandlerUrl,
data: JSON.stringify({})
data: JSON.stringify({
explorationVersion: explorationVersion
})
});
};
});
......
......@@ -245,6 +245,8 @@
}
}, LOADING_TIMEOUT_SECS);
// NOTE: Modified for OpenEdX to include exploration version.
/**
* Receives JSON-encoded messages from embedded Oppia iframes. Each
* message has a title and a payload. The structure of the payload
......@@ -252,14 +254,16 @@
* - 'heightChange': The payload is an Object with the following fields:
* height: a positive integer, and
* scroll: boolean -- scroll down to bottom if true.
* - 'explorationLoaded': The payload is an empty Object.
* - 'stateTransition': The payload is an Object with three keys:
* 'oldStateName', 'jsonAnswer' and 'newStateName'. All three of
* these have values of type String.
* - 'explorationLoaded': The payload is an Object with one key:
* explorationVersion.
* - 'stateTransition': The payload is an Object with four keys:
* 'oldStateName', 'jsonAnswer', 'newStateName' and
* 'explorationVersion'.
* - 'explorationReset': The payload is an Object with a single
* key-value pair. The key is 'stateName', and the value is of
* type String.
* - 'explorationCompleted': The payload is an empty Object.
* - 'explorationCompleted': The payload is an Object with one key:
* explorationVersion.
*/
window.addEventListener('message', function(evt) {
// Verify the origin of the message.
......@@ -284,7 +288,8 @@
case 'explorationLoaded':
that.loadingDiv.parentNode.removeChild(that.loadingDiv);
that.explorationHasLoaded = true;
window.OPPIA_PLAYER.onExplorationLoaded(iframeNode);
window.OPPIA_PLAYER.onExplorationLoaded(
iframeNode, data.payload.explorationVersion);
break;
case 'heightChange':
window.OPPIA_PLAYER.onHeightChange(
......@@ -293,7 +298,7 @@
case 'stateTransition':
window.OPPIA_PLAYER.onStateTransition(
iframeNode, data.payload.oldStateName, data.payload.jsonAnswer,
data.payload.newStateName);
data.payload.newStateName, data.payload.explorationVersion);
break;
case 'explorationReset':
// This needs to be set in order to allow the scrollHeight of the
......@@ -304,7 +309,8 @@
iframeNode, data.payload.stateName);
break;
case 'explorationCompleted':
window.OPPIA_PLAYER.onExplorationCompleted(iframeNode);
window.OPPIA_PLAYER.onExplorationCompleted(
iframeNode, data.payload.explorationVersion);
break;
default:
_log('Error: event ' + data.title + ' not recognized.');
......@@ -361,24 +367,27 @@
window.OPPIA_PLAYER.onHeightChangePostHook(iframeNode, newHeight);
},
onExplorationLoaded: function(iframeNode) {
onExplorationLoaded: function(iframeNode, explorationVersion) {
setTimeout(function() {
// Show the oppia contents after making sure the rendering happened.
iframeNode.style.position = 'inherit';
iframeNode.style.visibility = 'inherit';
iframeNode.style.top = 'inherit';
}, 0);
window.OPPIA_PLAYER.onExplorationLoadedPostHook(iframeNode);
window.OPPIA_PLAYER.onExplorationLoadedPostHook(
iframeNode, explorationVersion);
},
onStateTransition: function(iframeNode, oldStateName, jsonAnswer, newStateName) {
onStateTransition: function(
iframeNode, oldStateName, jsonAnswer, newStateName, explorationVersion) {
window.OPPIA_PLAYER.onStateTransitionPostHook(
iframeNode, oldStateName, jsonAnswer, newStateName);
iframeNode, oldStateName, jsonAnswer, newStateName, explorationVersion);
},
onExplorationReset: function(iframeNode, stateName) {
window.OPPIA_PLAYER.onExplorationResetPostHook(iframeNode, stateName);
},
onExplorationCompleted: function(iframeNode) {
window.OPPIA_PLAYER.onExplorationCompletedPostHook(iframeNode);
onExplorationCompleted: function(iframeNode, explorationVersion) {
window.OPPIA_PLAYER.onExplorationCompletedPostHook(
iframeNode, explorationVersion);
}
};
}(window, document));
......@@ -401,8 +410,10 @@ window.OPPIA_PLAYER.onHeightChangePostHook = function(iframeNode, newHeight) {
* Called when the exploration is loaded.
* @param {object} iframeNode The iframe node that is the source of the
* postMessage call.
* @param {int} explorationVersion The version number of the exploration.
*/
window.OPPIA_PLAYER.onExplorationLoadedPostHook = function(iframeNode) {
window.OPPIA_PLAYER.onExplorationLoadedPostHook = function(
iframeNode, explorationVersion) {
};
......@@ -413,9 +424,10 @@ window.OPPIA_PLAYER.onExplorationLoadedPostHook = function(iframeNode) {
* @param {string} oldStateName The name of the previous state.
* @param {string} jsonAnswer A JSON representation of the reader's answer.
* @param {string} newStateName The name of the destination state.
* @param {int} explorationVersion The version number of the exploration.
*/
window.OPPIA_PLAYER.onStateTransitionPostHook = function(
iframeNode, oldStateName, jsonAnswer, newStateName) {
iframeNode, oldStateName, jsonAnswer, newStateName, explorationVersion) {
};
......@@ -433,7 +445,9 @@ window.OPPIA_PLAYER.onExplorationResetPostHook = function(iframeNode, stateName)
* Called when the exploration is completed.
* @param {object} iframeNode The iframe node that is the source of the
* postMessage call.
* @param {int} explorationVersion The version number of the exploration.
*/
window.OPPIA_PLAYER.onExplorationCompletedPostHook = function(iframeNode) {
window.OPPIA_PLAYER.onExplorationCompletedPostHook = function(
iframeNode, explorationVersion) {
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment