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 zim.Wonder("wonderID", "client", "app");

// for this example we count times a button is pressed
var button = new zim.Button("CLICK"); // CLICK is the label
zim.centerReg(button, stage); // 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.

// 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

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

		// if the shapes are hitting then end the timer
		// this will send data to your Wonder report


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

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

// make tabs
var tabs = new zim.Tabs(400, 40, ["MOUSE", "CAT", "MONKEY"]);
tabs.selectedIndex = -1; // start with no selection
zim.centerReg(tabs, stage);
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);

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