DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:googleanalytics

This is an old revision of the document!


Google Analytics for DokuWiki

Compatible with DokuWiki

(current version)

plugin This tool allows you to set a code for use with Google Analytics, which allows you to track your visitors.

Last updated on
2009-05-25
Provides
Action

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to googletagmanager, hubspot, matomo, piwik, piwik2, referrers, userfly

Tagged with embed, google, statistics

License

It's not required, but please consider linking to this page or the main page from your site if you like this product.

Download

Before downloading or using this product, make sure you understand and accept the terms of the license.

After downloading, make sure to follow the install instructions or upgrading instructions below; trust me, they're worth reading.

  • Older downloads are available on request only.

Note: http://cloud.github.com/downloads/tatewake/dokuwiki-plugin-googleanalytics/googleanalytics-stable.tar.gz always points to the latest stable version!

Installation

Use the plugin manager to install, or…

  1. download the tarball/zip-file
  2. unpack it into <dokuwiki>/lib/plugins/
  3. login as admin and change the plugin in the configuration manager
  4. Google Analytics requires additional configuration for best use with DokuWiki (e.g., site search and goals). See Google Analytics integration for DokuWiki for details

using git:

% cd <dokuwiki>/lib/plugins/
% git clone git://github.com/tatewake/dokuwiki-plugin-googleanalytics.git googleanalytics

Debian install (or probably any other distribution):

# cd /usr/share/dokuwiki/lib/plugins/
# wget http://cloud.github.com/downloads/tatewake/dokuwiki-plugin-googleanalytics/googleanalytics-stable.tar.gz
# tar -xvzf googleanalytics-stable.tar.gz
# chown -Rv 33 googleanalytics/

Note: http://cloud.github.com/downloads/tatewake/dokuwiki-plugin-googleanalytics/googleanalytics-stable.tar.gz always points to the latest stable version!

About

This tool allows you to set a code for use with Google Analytics, which allows you to track your visitors.

Set the options for this plugin via the Configuration Settings menu from the DokuWiki admin menu. (It will be near the bottom of the page.)

Upgrading

To upgrade, remove the original lib/plugins/googleanalytics folder, and install the new version as instructed above. You may wish to make a note of your google analytics code first though.

What's New

May 25, 2009

  • Plugin is now an action plugin that requires no additional PHP code modification. Thanks to Mikhail I. Izmestev for this fix.

June 27, 2008

  • Fixed bug with tracking code
  • Added better check for admin users (removed old 'superuser' check)

Thanks to David Ordal for these fixes.

June 10, 2008

Updated to use the new Javascript library for Google Analytics. Thanks to Geoff W. and RJS for the contribution.

March 11, 2007

February 23, 2007

February 15, 2007

August 20, 2006

  • Initial release

Discussion

  • Start all subtopics using H2. (Heading 2.)

How to use Analytics plugin?

  1. Download and install the plugin in lib/plugins (you should have a folder like this: lib/plugins/googleanalytics)
  2. Copy and paste the below code into main.php (anywhere between <head> and </head>) which is in lib/tpl/monobook folder
<?php
if (file_exists(DOKU_PLUGIN.'googleanalytics/code.php')) include_once(DOKU_PLUGIN.'googleanalytics/code.php');
if (function_exists('ga_google_analytics_code')) ga_google_analytics_code();
?>
  1. Login to your Google analytics account and add the URL of your wiki
  2. Copy the tracking code (e.g., UA-1234-1)
  3. Login to your wiki and go to admin. click on Google Analytics then paste the tracking code into the field.
  4. Wait a few minutes and you should be getting data in your google analytics account.

Wrong version info

The last version of the plugin identifies as 2007-02-23 instead of 2007-03-11 in getInfo(). Should be fixed.

Code Location in Template

Hi! This is a really handy little plugin, thanks for putting it together.

I hope this isn't getting into too much semantics, but I am a little confused about the location of the code in the template. The plugin instructions say to place the code in the <head> section (and the monbook template has it pre-placed there of course). This then results with both the google <script> definition and actual urchinTracker(); function call to appear in the head on rendered pages. Makes sense. However, the Google Analytics site instructs one to place all the tracking code into the <body> section (specifically just before the </body> tag).

From what I have seen, both code locations (in <head> or in <body>) work - ie. google Analytics reports that data is being collected, but why the discrepancy? Does it depend in the client's browser? What location is “best” or most universal? Does it matter?

Best. — Ryan Jacobs

After looking through various Google sources and groups, it seems the the old method was to place the code in the <head>, and that now, possible with newer versions of Analytics, it's best to put the code just before the </body> tag (also as recommended by Google directly). I suppose either location will “work”, but there could be performance issues, etc., when putting the code in the <head>. Are the instructions and plugin notes simply outdated in this respect, or it there still a special reason to be placing the code in the <head> section?

Cheers — Ryan Jacobs

ACL: WHICH CODE?

Nice plugin, but I found some problem. 1. I set a new google analytics account and got the code, that is composed by SIX row

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "....";
urchinTracker();
</script>

2. I install the plugin and put the code in the main.php page of my monobook

<?php 
if (file_exists(DOKU_PLUGIN.'googleanalytics/code.php')) include_once(DOKU_PLUGIN.'googleanalytics/code.php');
if (function_exists('ga_google_analytics_code')) ga_google_analytics_code();
?>

3. I go to my ACL page, and would put the code, but it is very small form.

So, what do I have to do with the google six raw code? Where the mistake? Best. — hirzel75


AUTOREPLY
From Terence's holy Words:

There are two different “codes” that people usually confuse…
1. There's the HTML code that google analytics gives you:

<script src="http://www.google-analytics.com/urchin.js"
type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "....";
urchinTracker();
</script>

2. And then there's the unique ACCOUNT code within *that* HTML code:

_uacct = "....";

Which actually says something like this:

 _uacct = "UA-12345";

The reason that the code field is so small in the plugin, is that it is looking simply for:

 UA-12345

Or whatever your unique “code” is.)

The plugin generates the HTML code, given that you provide an ACCOUNT code.

So the answer to question 3 is: paste only UA-12345 hirzel75

The plug-in seems to work well for the DokuWiki pages. What I would like to have on top is: whenever a user clicks on a link that does not lead to a wiki page but rather to a media file or download or to an external link that that gets tracked as well. (Olaf)

That's way beyond the scope of this plugin.

Here's just some thoughts on why…

  • Google Analytics itself is written by Google, not me.
    • This plugin just makes it easier to integrate Google Analytics with your site.
  • Google Analytics is in JavaScript.
    • There's only so much you can do with JavaScript
      • Runs on the client side, not the server side
      • Much of what you want would be reliant on the server side
    • You can't run JavaScript from non-HTML documents, so…
      • Direct links to files from other sites cannot be tracked via this plugin.
  • Google Analytics already tracks outgoing links.

These are just a few reasons that come to mind; the primary thing is you'd want something that runs server side, which this plugin really doesn't do. I'd almost say you could modify the referrers plugin to do this, but in reality, I doubt DokuWiki is flexible enough for you to track media files (or downloads) via a plugin. For this alone you'd need to modify DokuWiki's source.

Otherwise external links are already “tracked” by Google Analytics somewhat (I believe they call them “bounces” but I'm not sure.) I say somewhat because it's not really as if they give you a verbose listing of every outgoing link or every incoming link… (Which is why I wrote the referrers plugin.)

Hope that helps. — Terence J. Grant 02/22/2007 20:09

Hi Terence: just to make this clear - I am not complaining! ;→ WRT to your reply: I have to admit I am far from being a DokuWiki or PHP expert. Nevertheless, the links for media/downloads must be encoded somehow somewhre in the DokuWiki code, and the idea would be specialize the creation of these links such that they include an onClick call to a Google Analytics JavaScript call. We have already done that for a website that has its own way of creating download links. At the moment a guy who does PHP and DokuWiki programming for us is chewing on how to meet this need in the context of our DokuWiki sites. Once he has figured out how to do it I will be more than happy to share his findings here. So maybe you might be in a position to extend the scope of your nice plug-in should you feel like it. (Olaf)

Ah, I see; you're correct in this, it should be possible to track additional things via onClick. I'll look into syntax plugins and see how easy it would be to integrate this in. I can't really give you a time line on this though since I've not done syntax plugins before. — Terence J. Grant 02/23/2007 17:17

GeoURL for DokuWiki

Hi! I have made a DokuWiki plugin based on your. GPLed, GeoURL for DokuWiki. Regards, –KB

little bug

line 39, code.php should be changed to:

if (is_writable($ga_file) || is_writable(dirname(__FILE__)))

is_writable($ga_file) will fail if the file does not exist, although the directory is writeable.

http://de2.php.net/manual/en/function.is-writable.php seems that function is buggy in general :\
contact: bernd [at] bzed [dot] de

google adsense

I've grabbed your code and made http://bzed.de/code/dokuwiki/googleads out of it. While doing it I've realized, that you could improve the analytics plugin by adding addslashes/stripslashes at the appropriate places to stop people from destroying their config file by entering ' accidentally. — bzed 2007-03-14

Which file to add the code to?

Which file should I add the code to? I try adding it to footer.html but I cannot save it as .html and if I save it as .php, the template does not work. Thanks for your help.

Add the code to main.php, somewhere between the <head> and </head> tags. — Terence J. Grant 05/27/2007 12:50

little bug - count admin

line 63, code.php should be changed from:

if ($ga_settings['dontcountadmin'] && $_SERVER['REMOTE_USER'] == conf['superuser']) return;

to:

if ($ga_settings['dontcountadmin'] && $INFO['isadmin'] = 1 ) return;

contact: vaclav [at] koranek [dot] eu

configuration file

line 13, 37 in code.php : you sould use $ga_file = DOKU_CONF.'ga_pref.php'; to be able to use the plugin in differents wikis with differents configurations.

contact thomas [dot] mortagne [at] gmail [dot] com

Makin' it configurable

Hi, upon installing your plugin, I have edited your ga_google_analytics_code function so that it includes:

  <?php
  function ga_google_analytics_code($ga_tracker='UseNew') // notice new variable
  {
      global $ga_loaded, $ga_settings, $INFO;
      if ($ga_settings['code'])
      {
              if ($ga_settings['dontcountadmin'] && $INFO['isadmin']) return;
              if ($ga_settings['dontcountusers'] && $_SERVER['REMOTE_USER']) return;
	if ($ga_tracker == 'UseNew') {
		ptln('<script type="text/javascript">');
		ptln('var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");');
		ptln('document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));');
		ptln('</script>');
		ptln('<script type="text/javascript">');
		ptln('var pageTracker = _gat._getTracker("'.$ga_settings['code'].'");');
		ptln('pageTracker._initData();');
		ptln('pageTracker._trackPageview();');
		ptln('</script>');
	} else if ($ga_tracker == 'UseOld') {
		ptln('<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">');
		ptln('</script>');
		ptln('<script type="text/javascript">');
		ptln('_uacct = "'.$ga_settings['code'].'";');
		ptln('urchinTracker();');
		ptln('</script>');
	}
             
      }
  }
  ?>

Obviously this allows a user to choose the kind of google analytics tracker he wants to use. I actually use the old one :-).

contact miki [dot] antena [at] gmail [dot] com

plugin/googleanalytics.1288538134.txt.gz · Last modified: 2010-10-31 16:15 by lupo49

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki