ZIMjs - Wonder Examples - Micro Stats

// wonderID is e-mailed to you when you sign up
// client is your client's name that you provide
// app is the app for which you are recording data
// you can also pass an optional note
var wonder = new Wonder("wonderID", "client", "app");

// COUNT EXAMPLE
// for this example we count times a button is pressed
var button = new Button().center(); // will center and add to stage
button.on("click", function(){

	// records an entry for this keyword in your stats
	// along with date, time, session, etc.
	wonder.count("wow");

});
// TIME EXAMPLE
// assuming we have our Wonder object from above
// (you only need one Wonder object)
// start the timer counting for a keyword called "test"
// this will record nothing until you timeEnd()
// or you timeStart() again
// you can also timePause() and timeUnpause()
// see DOCS for more functionality and information
wonder.timeStart("test");

// add the circle
var circle = new Circle(100, "red").center().drag();
circle.on("pressup", function(){
	if (circle.hitTestRect(square)) {

		// if the shapes are hitting then end the timer
		// this will send data to your Wonder report
		wonder.timeEnd("test");

	}
});

// add the square to a random location on stage
var square = new Rectangle(100, 100, "yellow")
	.pos(rand(stageW-100), rand(stageH-100));

// ORDER EXAMPLE
// assuming we have our Wonder object from above
// (you only need one Wonder object)

// make tabs
var tabs = new Tabs(400, 40, ["MOUSE", "CAT", "MONKEY"])
	.center();
tabs.selectedIndex = -1; // start with no selection
var count = 0; // perhaps get the first four presses
tabs.on("change", function(){

	// record which tab was pressed
	// this gets stored under keyword animal
	wonder.order("animal", tabs.text);

	count++;
	// turn the order recording off for "animal"
	if (count == 4) wonder.orderOff("animal");

});