Google Analytics"

From Documentation
m (Created page with '{{ZKDevelopersReferencePageHeader}} To track the Ajax traffic with [http://www.google.com/analytics/ Google Analytics] or other statistic services, you have to override a client…')
 
m
Line 5: Line 5:
 
Here we use Google Analytics as an example to illustrate how to override it.
 
Here we use Google Analytics as an example to illustrate how to override it.
  
<source lang="xml">
+
<source lang="java">
<script defer="true"><![CDATA[
 
 
try {
 
try {
 
var pageTracker = _gat._getTracker("UA-xxxx"); //whatever code your website is assigned
 
var pageTracker = _gat._getTracker("UA-xxxx"); //whatever code your website is assigned
Line 27: Line 26:
 
}catch(e){
 
}catch(e){
 
}
 
}
]]></script>
 
 
</source>
 
</source>
  

Revision as of 09:09, 29 November 2010

To track the Ajax traffic with Google Analytics or other statistic services, you have to override a client-side API: zAu.beforeSend(String, Event, Desktop). This method will be called each time ZK Client is about to send an Ajax request to the server. You could override it to record the requests on any statistic service you prefer.

Here we use Google Analytics as an example to illustrate how to override it.

try {
var pageTracker = _gat._getTracker("UA-xxxx"); //whatever code your website is assigned
pageTracker._setDomainName("zkoss.org");
pageTracker._initData();
pageTracker._trackPageview();

zk.override(zAu, "beforeSend", function (uri, req) {
	try {
		var t = req.target;
		if (t && t.id && (!req.opts || !req.opts.ignorable)) {
			var data = req.data||{},
				value = data.items && data.items[0]?data.items[0].id:data.value;
			pageTracker._trackPageview(uri +"/" + t.id + "/" + req.name + (value?"/"+value:""));
		}
	} catch (e) {
	}
	return zAu.$beforeSend(uri, req);
});
}catch(e){
}

Of course, you could only record the information you are interested by examining Event.name.

Version History

Last Update : 2010/11/29


Version Date Content
     



Last Update : 2010/11/29

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.