1 if(!dojo._hasResource["dojox.analytics._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.analytics._base"] = true;
3 dojo.provide("dojox.analytics._base");
5 dojox.analytics = function(){
6 //where we store data until we're ready to send it off.
11 //id of messages for this session/page
15 this.sendInterval=dojo.config["sendInterval"] || 5000;
16 this.inTransitRetry=dojo.config["inTransitRetry"] || 200;
17 this.dataUrl=dojo.config["analyticsUrl"] || dojo.moduleUrl("dojox.analytics.logger", "dojoxAnalytics.php");
18 this.sendMethod = dojo.config["sendMethod"] || "xhrPost";
20 this.maxRequestSize = 2000;
22 this.maxRequestSize = dojo.config["maxRequestSize"] || 4000;
25 //while we can go ahead and being logging as soon as this constructor is completed
26 //we're not going to schedule pushing data to the server until after the page
27 //has completed loading
28 dojo.addOnLoad(this, "schedulePusher");
29 dojo.addOnUnload(this, "pushData", true);
32 dojo.extend(dojox.analytics, {
33 schedulePusher: function(interval){
35 // schedule the data pushing routines to happen in interval ms
36 setTimeout(dojo.hitch(this, "checkData"), interval||this.sendInterval);
39 addData: function(dataType, data){
41 // add data to the queue. Will be pusshed to the server on the next
44 if (arguments.length>2){
46 for(var i=1;i<arguments.length;i++){
52 this._data.push({plugin: dataType, data: data});
55 checkData: function(){
58 this.schedulePusher(this.inTransitRetry);
62 if (this.pushData()){return}
63 this.schedulePusher();
68 // pushes data to the server if any exists. If a push is done, return
69 // the deferred after hooking up completion callbacks. If there is no data
70 // to be pushed, return false;
71 if (this._data.length>0){
73 this._inTransit=this._data;
76 switch(this.sendMethod){
78 def = dojo.io.script.get({url: this.getQueryPacket(), preventCache: 1, callbackParamName: "callback"});
82 console.info("post send: ", this._inTransit);
83 def = dojo.xhrPost({url:this.dataUrl, content: {id: this._id++, data: dojo.toJson(this._inTransit)}});
86 def.addCallback(this, "onPushComplete");
92 getQueryPacket: function(){
94 var content = {id: this._id++, data: dojo.toJson(this._inTransit)};
96 //FIXME would like a much better way to get the query down to lenght
97 var query = this.dataUrl + '?' + dojo.objectToQuery(content);
98 if (query.length>this.maxRequestSize){
99 this._data.unshift(this._inTransit.pop());
102 //console.log("script send: ", this._inTransit, " Remaining in queue: ", this._data.length);
108 onPushComplete: function(results){
110 // if our data push was successfully, remove the _inTransit data and schedule the next
112 if (this._inTransit){
113 delete this._inTransit;
116 if (this._data.length>0){
117 this.schedulePusher(this.inTransitRetry);
119 this.schedulePusher();
124 //create the analytics singleton
125 dojox.analytics = new dojox.analytics();