0

Tracking ajaz requests with Google analytics

asked 2010-05-21 01:43:56 +0800

kapil4ya gravatar image kapil4ya
172 2

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

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2010-05-21 07:25:53 +0800

madruga0315 gravatar image madruga0315 flag of Brazil
937 2 12

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

link publish delete flag offensive edit

answered 2010-05-21 23:57:46 +0800

kapil4ya gravatar image kapil4ya
172 2

Does anyone has any knowledge about this? The docs are very unclear about this.

link publish delete flag offensive edit

answered 2010-05-23 22:07:39 +0800

PeterKuo gravatar image PeterKuo
481 2

Please refer to
http://docs.zkoss.org/wiki/Client_Side_Programming#Override_a_Default_Widget_Method_for_Whole_Application

link publish delete flag offensive edit

answered 2010-05-24 08:17:38 +0800

madruga0315 gravatar image madruga0315 flag of Brazil
937 2 12

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

link publish delete flag offensive edit

answered 2010-06-03 21:24:48 +0800

PeterKuo gravatar image PeterKuo
481 2

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);
};

link publish delete flag offensive edit

answered 2010-06-14 03:06:31 +0800

kapil4ya gravatar image kapil4ya
172 2

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!

link publish delete flag offensive edit

answered 2010-06-17 21:21:44 +0800

iantsai gravatar image iantsai
2755 1

you can trace the code inside ZKDemo, at /userguide/index.zul there's a runnable code which is used in online ZKDemo Service.

link publish delete flag offensive edit

answered 2011-12-27 02:22:42 +0800

moonline gravatar image moonline
3

<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>

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-05-21 01:43:56 +0800

Seen: 950 times

Last updated: Dec 27 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More