本稿は「plugin:googleanalytics [DokuWiki]」(リンク)の記事の拙訳版です。
---- plugin ---- 説明 : Google Analyticsのコードを埋め込む事で、あなたのサイトへの訪問者の記録を行うことができます。 作成者: Terence J. Grant メール: tjgrant@tatewake.com タイプ: action 最終更新日: 2009-05-25 compatible : (current version) 依存するプラグイン: 競合するプラグイン: 似ているプラグイン: piwik, referrers タグ : google, statistics, embed ダウンロード :http://cloud.github.com/downloads/tatewake/dokuwiki-plugin-googleanalytics/googleanalytics-stable.tar.gz ソースリポジトリ :https://github.com/tatewake/dokuwiki-plugin-googleanalytics ----
It's not required, but please consider linking to this page or the main page from your site if you like this product.
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.
Note: http://cloud.github.com/downloads/tatewake/dokuwiki-plugin-googleanalytics/googleanalytics-stable.tar.gz always points to the latest stable version!
Use the plugin manager to install, or…
<dokuwiki>/lib/plugins/
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!
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.)
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.
Thanks to David Ordal for these fixes.
Updated to use the new Javascript library for Google Analytics. Thanks to Geoff W. and RJS for the contribution.
<?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(); ?>
For latest version your don't need add any php code, see above
– quabug 2010/11/12
The last version of the plugin identifies as 2007-02-23 instead of 2007-03-11 in getInfo(). Should be fixed.
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
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…
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
Hi! I have made a DokuWiki plugin based on your. GPLed, GeoURL for DokuWiki. Regards, –KB
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@bzed.de
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 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
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@koranek.eu
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.mortagne@gmail.com
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.antena@gmail.com
(2011/12/30)
<?php $lang['GAID'] = 'Google Analitycs ID'; $lang['dont_count_admin'] = 'Nie zliczaj: admin/superuser'; $lang['dont_count_users'] = 'Nie zliczaj zalogownych użytkowników';