Add user activity logging to tutorial

This commit is contained in:
Ryan Huffman 2016-09-20 08:21:44 -07:00
parent 5714535fb4
commit 4efeb928e2
3 changed files with 31 additions and 2 deletions

View file

@ -24,6 +24,16 @@ void UserActivityLoggerScriptingInterface::toggledAway(bool isAway) {
logAction("toggled_away", { { "is_away", isAway } });
}
void UserActivityLoggerScriptingInterface::tutorialProgress(QString stepName, int stepNumber, float secondsToComplete, float tutorialElapsedTime) {
logAction("tutorial_progress", {
{ "step", stepName },
{ "stepNumber", stepNumber },
{ "secondsToComplete", secondsToComplete },
{ "tutorial_elapsed_time", tutorialElapsedTime }
});
}
void UserActivityLoggerScriptingInterface::logAction(QString action, QJsonObject details) {
QMetaObject::invokeMethod(&UserActivityLogger::getInstance(), "logAction",
Q_ARG(QString, action),

View file

@ -23,6 +23,7 @@ public:
Q_INVOKABLE void enabledEdit();
Q_INVOKABLE void openedMarketplace();
Q_INVOKABLE void toggledAway(bool isAway);
Q_INVOKABLE void tutorialProgress(QString stepName, int stepNumber, float secondsToComplete, float tutorialElapsedTime);
private:
void logAction(QString action, QJsonObject details = {});

View file

@ -210,6 +210,7 @@ function playSuccessSound() {
///////////////////////////////////////////////////////////////////////////////
var stepDisableControllers = function(name) {
this.tag = name;
this.shouldLog = false;
}
stepDisableControllers.prototype = {
start: function(onFinish) {
@ -959,10 +960,15 @@ TutorialManager = function() {
var currentStepNum = -1;
var currentStep = null;
var startedTutorialAt = 0;
var startedLastStepAt = 0;
var self = this;
this.startTutorial = function() {
currentStepNum = -1;
currentStep = null;
startedTutorialAt = Date.now();
STEPS = [
new stepDisableControllers("step0"),
new stepOrient("orient"),
@ -984,6 +990,17 @@ TutorialManager = function() {
this.startNextStep();
}
this.onFinish = function() {
if (currentStep && currentStep.shouldLog !== false) {
var timeToFinishStep = (Date.now() - startedLastStepAt) / 1000;
var tutorialTimeElapsed = (Date.now() - startedTutorialAt) / 1000;
UserActivityLogger.tutorialProgress(
currentStep.tag, currentStepNum, timeToFinishStep, tutorialTimeElapsed);
}
self.startNextStep();
}
this.startNextStep = function() {
if (currentStep) {
currentStep.cleanup();
@ -1000,14 +1017,15 @@ TutorialManager = function() {
} else {
print("Starting step", currentStepNum);
currentStep = STEPS[currentStepNum];
currentStep.start(this.startNextStep);
startedLastStepAt = Date.now();
currentStep.start(this.onFinish);
return true;
}
}.bind(this);
this.restartStep = function() {
if (currentStep) {
currentStep.cleanup();
currentStep.start(this.startNextStep);
currentStep.start(this.onFinish);
}
}