0

Integrating Google Analytics into zul pages

asked 2011-07-26 11:25:13 +0800

valmar gravatar image valmar
925 2 13
http://www.timo-ernst.net

Hi everyone,

I am looking for a way to add the script provided by Google Analytics into a zul page.

According to Google, the script must be place right before the </head> tag.

I already read this: http://books.zkoss.org/wiki/ZK_Developer's_Reference/Integration/Google_Analytics
But this is not what I want.

I don't want to track ajax request. All I want is that the Google Analytics script should be run once the zul page is opened. That's it. No ajax.

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2011-07-26 12:20:35 +0800

pymsoft gravatar image pymsoft
133 5

I use this code in login.zul

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'YOUR ACCOUNT']);
  _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>

Best regards.

link publish delete flag offensive edit

answered 2011-07-26 18:15:39 +0800

valmar gravatar image valmar
925 2 13
http://www.timo-ernst.net

Yeah, but where exactly do you put it in the ZUL file?
I am asking because Google says it's best to put it before the </head> tag in the html site.

link publish delete flag offensive edit

answered 2011-07-27 02:37:49 +0800

pymsoft gravatar image pymsoft
133 5

Try with this code:

Publish and then see source code from html.

<zk>
	<window id="win" width="400px" top="100px"
		style="margin-left:auto;margin-right:auto;margin-top:150px">


<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-15607597-3']);
  _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>
	</window>

</zk>


Best regards

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: 2011-07-26 11:25:13 +0800

Seen: 291 times

Last updated: Jul 27 '11

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