-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Guys, I need to make use of Google analytics, I am using ZK EE 5.0.2 library.
On this url : http://docs.zkoss.org/wiki/New_Features_of_ZK_5.0.2
I see a section named " Tracking Ajax requests with Google Analytics" which says you need to put a particular code in your zul files. I am lost as to where I need to put that code?
Please can someone help me out here ?
Thanks
Agreed,
I also would like a more in depth view on this feature.
Also a demo with some sample data, showing the results on GA would be great to taste it and have a idea of the impact of this feature.
King regards,
Madruga
Hi perter,
Thanks for the javadoc. But we're looking for more info on the script itself, how it works, how to configure, sample data etc...
Could/Is this feature being used on zk forum?
Regards,
Madruga
You can look into the au.js source code of zk.
beforeSend() is called inside sendNow()
/** Enforces all pending AU requests of the specified desktop to send immediately
* @param Desktop dt
* @return boolean whether it is sent successfully. If it has to wait
* for other condition, this method returns false.
*/
sendNow: function (dt) {
And pageTracker._trackPageview is defined by google analytic to log such event.
Therefore, the script is enough to log the event.
var auBfSend = zAu.beforeSend;
zAu.beforeSend = function (uri, req) {
try {
var target = req.target;
if (target.id) {
var data = req.data||{},
value = data.items && data.items[0]?data.items[0].id:data.value;
pageTracker._trackPageview((target.desktop?target.desktop.requestPath:"") + "/" + target.id + "/" + req.name + (value?"/"+value:""));
}
} catch (e) {
}
return auBfSend(uri, req);
};
Thank you Peter for the help, here is the problem I am facing...
I have included this google analytics code in each zul page of our application...
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script>
Where the account property ID is properly set.
Now, I make an entry in the zk.xml as follows to execute a java script code each time a request comes :
<language-config> <addon-uri>/WEB-INF/analytics-lang-addon.xml</addon-uri> </language-config>
And the contents of the analytics-lang-addon.xml are as follows -
<?xml version="1.0" encoding="UTF-8"?> <language-addon> <language-name>xul/html</language-name> <javascript src="/js/analytics.js" charset="UTF-8"/> </language-addon>
So, eventually, this js gets called each time, we are half done till now. The analytics.js looks something like -
var auBfSend = zAu.beforeSend; zAu.beforeSend = function (uri, req) { try { var target = req.target; if (target.id) { var data = req.data||{}, value = data.items && data.items[0]?data.items[0].id:data.value; pageTracker._trackPageview((target.desktop?target.desktop.requestPath:"") + "/" + target.id + "/" + req.name + (value?"/"+value:"")); } } catch (e) { alert('error while logging '+e.message); } alert('value '+auBfSend(uri, req)); return auBfSend(uri, req); };
With this code, I am able to see something being returned, but at the same time it says in the catch statement that "pageTracker is not defined".
With this analytics module we are having, the page views requests are logged but the ajax requests are not logged.
Where do you thing I am missing the things? I suppose, I am on the right track but just can not get all the things work together in unison.
Thank you again!
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; http://www.lalinguaarabapertutti.com/s.parentNode.insertBefore(ga, s);
i tried it it is working
})();
</script>
Asked: 2010-05-21 01:43:56 +0800
Seen: 950 times
Last updated: Dec 27 '11