root / trunk / web / dojo / dojox / analytics / _base.js @ 11
History | View | Annotate | Download (2.12 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dojox.analytics._base"]){ |
| 9 |
dojo._hasResource["dojox.analytics._base"]=true; |
| 10 |
dojo.provide("dojox.analytics._base");
|
| 11 |
dojox.analytics=function(){ |
| 12 |
this._data=[];
|
| 13 |
this._id=1; |
| 14 |
this.sendInterval=dojo.config["sendInterval"]||5000; |
| 15 |
this.inTransitRetry=dojo.config["inTransitRetry"]||200; |
| 16 |
this.dataUrl=dojo.config["analyticsUrl"]||dojo.moduleUrl("dojox.analytics.logger","dojoxAnalytics.php"); |
| 17 |
this.sendMethod=dojo.config["sendMethod"]||"xhrPost"; |
| 18 |
this.maxRequestSize=dojo.isIE?2000:dojo.config["maxRequestSize"]||4000; |
| 19 |
dojo.addOnLoad(this,"schedulePusher"); |
| 20 |
dojo.addOnUnload(this,"pushData",true); |
| 21 |
}; |
| 22 |
dojo.extend(dojox.analytics,{schedulePusher:function(_1){
|
| 23 |
setTimeout(dojo.hitch(this,"checkData"),_1||this.sendInterval); |
| 24 |
},addData:function(_2,_3){ |
| 25 |
if(arguments.length>2){ |
| 26 |
var c=[];
|
| 27 |
for(var i=1;i<arguments.length;i++){ |
| 28 |
c.push(arguments[i]);
|
| 29 |
} |
| 30 |
_3=c; |
| 31 |
} |
| 32 |
this._data.push({plugin:_2,data:_3}); |
| 33 |
},checkData:function(){ |
| 34 |
if(this._inTransit){ |
| 35 |
this.schedulePusher(this.inTransitRetry); |
| 36 |
return;
|
| 37 |
} |
| 38 |
if(this.pushData()){ |
| 39 |
return;
|
| 40 |
} |
| 41 |
this.schedulePusher();
|
| 42 |
},pushData:function(){ |
| 43 |
if(this._data.length){ |
| 44 |
this._inTransit=this._data; |
| 45 |
this._data=[];
|
| 46 |
var _4;
|
| 47 |
switch(this.sendMethod){ |
| 48 |
case "script": |
| 49 |
_4=dojo.io.script.get({url:this.getQueryPacket(),preventCache:1,callbackParamName:"callback"});
|
| 50 |
break;
|
| 51 |
case "xhrPost": |
| 52 |
default:
|
| 53 |
_4=dojo.xhrPost({url:this.dataUrl,content:{id:this._id++,data:dojo.toJson(this._inTransit)}});
|
| 54 |
break;
|
| 55 |
} |
| 56 |
_4.addCallback(this,"onPushComplete"); |
| 57 |
return _4;
|
| 58 |
} |
| 59 |
return false; |
| 60 |
},getQueryPacket:function(){ |
| 61 |
while(true){ |
| 62 |
var _5={id:this._id++,data:dojo.toJson(this._inTransit)}; |
| 63 |
var _6=this.dataUrl+"?"+dojo.objectToQuery(_5); |
| 64 |
if(_6.length>this.maxRequestSize){ |
| 65 |
this._data.unshift(this._inTransit.pop()); |
| 66 |
this._split=1; |
| 67 |
}else{
|
| 68 |
return _6;
|
| 69 |
} |
| 70 |
} |
| 71 |
},onPushComplete:function(_7){ |
| 72 |
if(this._inTransit){ |
| 73 |
delete this._inTransit; |
| 74 |
} |
| 75 |
if(this._data.length>0){ |
| 76 |
this.schedulePusher(this.inTransitRetry); |
| 77 |
}else{
|
| 78 |
this.schedulePusher();
|
| 79 |
} |
| 80 |
}}); |
| 81 |
dojox.analytics=new dojox.analytics();
|
| 82 |
} |