1,007
edits
(//) |
|||
| Line 190: | Line 190: | ||
That's it! We're now recording data. Try it out! | That's it! We're now recording data. Try it out! | ||
== Recording Data on Study Startup == | |||
It's often very useful to record some data, and/or do other startup tasks, when the study starts up. For some studies, e.g. ones that can collect all their data immediately rather than waiting to observe UI events, study startup may be the only time we want to collect data at all. | |||
For this, we simply override the '''onExperimentStartup()''' method of the global observer class: | |||
BackButtonGlobalObserver.prototype.onExperimentStartup = function(store) { | |||
// store is a reference to the live database table connection | |||
// you MUST call the base class onExperimentStartup and give it the store | |||
// reference: | |||
BackButtonGlobalObserver.superClass.onExperimentStartup.call(this, store); | |||
// Put your other code here! | |||
console.info("Back button study is starting up!"); | |||
}; | |||
I strongly recommend recording a study version number whenever the study starts up. This way, if you have need to modify your study later, you can update the study version number, and then when we're analyzing the data we can tell apart data that came from the earlier version and data that came from the later version. (You could also make a column for the study version and put in the study version with every event recorded, but that will unnecessarily increase the size of the final data upload...) | |||
const EVENT_CODE_STUDY_STARTUP = 0; | |||
exports.experimentInfo = { | |||
versionNumber: 1, | |||
// etc etc. | |||
}; | |||
BackButtonGlobalObserver.prototype.onExperimentStartup = function(store) { | |||
BackButtonGlobalObserver.superClass.onExperimentStartup.call(this, store); | |||
record({event_code: EVENT_CODE_STUDY_STARTUP, | |||
value: exports.experimentInfo.versionNumber, | |||
timestamp: Date.now()}); | |||
console.info("Back button study is starting up!"); | |||
}; | |||
Coming up with an appropriate schema for this is left as an exercise for the reader. | |||
edits