Labs/Test Pilot/Experiment Tutorial: Difference between revisions

Jump to navigation Jump to search
No edit summary
Line 111: Line 111:


== Recording an Event to the Data Store ==
== Recording an Event to the Data Store ==
Recording events is generally done through your GlobalObserver instance.  If you're using the base class and you initialized it correctly, you can use the superclass record() method.  This method's signature is:
record: function(event, callback)
Recording to the database is an asynchronous action, so you can optionally provide a callback function which will be called when the recording is done.  If you don't need to do anything after the recording is done (you usually won't) then you can leave out the callback argument.  If you provide it, your callback function will get a single argument which is true on successful recording and false on failure.
The record() method automatically respects the state of Firefox Private Browsing Mode, and will record nothing (passing '''false''' to your callback) when private browsing mode is turned on.
Since you're exporting your GlobalObserver instance already, you'll be able to refer to this instance anywhere in your study code module as '''exports.handlers'''.  So your call to the record method might look like:
exports.handlers.record({});
The '''event''' argument to record() must be an object with property names matching the names of the columns in your database.  Remember that these columns are defined according to your module's '''exports.dataStoreInfo''' object.  So let's define a data store with two columns, one for the name of the button clicked and the other for the timestamp of when it was clicked:
exports.dataStoreInfo = {
  fileName: "testpilot_backbutton_results.sqlite",
  tableName: "testpilot_backbutton_study",
  columns: [
    {property: "button_name", type: BaseClasses.TYPE_STRING,
      displayName: "Button Clicked"},
    {property: "timestamp", type: BaseClasses.TYPE_DOUBLE,
      displayName: "Time of Click"}
  ]
};
(Timestamps should always be TYPE_DOUBLE as they will get truncated if you use TYPE_INT_32.)
We now need to pass in objects that have a '''button_name''' property and a '''timestamp''' property.  Our call to the record method is:
exports.handlers.record({button_name: "", timestamp: ""});
Let's put that into its proper context in that listener that we registered on the back button in the previous step:
1,007

edits

Navigation menu