define(["Ti/_","Ti/_/dom","Ti/_/has","Ti/_/lang","Ti/App","Ti/Platform"],function(e,t,n,i,a,s){function o(){var e=localStorage.getItem("ti:analyticsEvents");return e?JSON.parse(e):[]}function r(e){localStorage.setItem("ti:analyticsEvents",JSON.stringify(e))}function d(e){if(e&&"object"==typeof e&&e.success){var t,n=y[e.callback],i=[],a=o(),s=0,d=a.length;if(n){for(;d>s;)t=a[s++],~n.indexOf(t.id)||i.push(t);r(i)}}}var u,c=window,l=(require.is,require.config,a.analytics),p=null,f="https://api.appcelerator.net/p/v3/mobile-web-track/"+a.guid,y={},m=6e4,g={add:function(t,n,i,a){if(l){var s=o();s.push({id:e.uuid(),type:t,evt:n,ts:(new Date).toISOString().replace("Z","+0000"),data:i}),r(s),this.send(a)}},send:function(i){if(l){var r,c=Math.floor(1e6*Math.random()),S=Date.now(),h=[],v=[],T=sessionStorage.getItem("ti:sessionId"),I=sessionStorage.getItem("ti:analyticsSeqId"),w=o(),O=0,b=w.length;if("string"==typeof I&&(I=JSON.parse(I)),clearTimeout(u),b&&(i||null==p||S-p>=m)){for(T||(T=e.uuid()),null==I&&(I=0);b>O;)r=w[O++],h.push(r.id),v.push({id:r.id,mid:s.id,rdu:null,type:r.type,aguid:a.guid,event:r.evt,seq:I++,ver:"2",deploytype:a.deployType,sid:T,ts:r.ts,data:r.data}),"ti.end"==r.type&&(I=0,T=e.uuid());if(sessionStorage.setItem("ti:sessionId",T),sessionStorage.setItem("ti:analyticsSeqId",I),y[c]=h,p=S,v=JSON.stringify(v),n("ti-analytics-use-xhr")){var q=new XMLHttpRequest;q.onreadystatechange=function(){if(4==q.readyState&&200==q.status)try{var e=JSON.parse(q.responseText);e.callback=c,d(e)}catch(t){}},q.open("POST",f,!0),q.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),q.send("content="+encodeURIComponent(v))}else{var J=document.body,N="analytics"+c,k=t.create("iframe",{id:N,name:N,style:{display:"none"}},J),x=t.create("form",{action:f+"?callback="+c+"&output=html",method:"POST",style:{display:"none"},target:N},J);t.create("input",{name:"content",type:"hidden",value:v},x),setTimeout(function(){function e(){setTimeout(function(){t.destroy(x),t.destroy(k)},1)}k.onload=e,k.onerror=e,x.submit()},25)}}u=setTimeout(function(){g.send(1)},m)}}};return require.on(c,"message",function(e){d(e.data)}),g});