====== ganalytics plugin ====== ---- plugin ---- description: Displays Google analytics data using Google Chart API author : Paul Troost email : ganalytics@greenbird.info type : syntax lastupdate : 2009-05-04 compatible : >=2009-02-14 depends : conflicts : similar : tags : !discontinued, media, images, diagram, chart, google, statistics, embed ---- ===== Download and Installation ===== Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. Google Analytics requires additional configuration for best use with DokuWiki (e.g., site search and goals). See [[http://en.seowiki.info/best_practices/seo_optimized_dokuwiki/integration/google_analytics|Google Analytics integration for DokuWiki]] for details. ^ Download | [[http://www.greenbird.info/_media/dokuwiki/ganalytics.zip|ganalytics.zip (20.8 Kb)]] | FIXME (download link is broken) Blog entry: http://greenbird.tweakblogs.net/blog/3420/ganalytics-dokuwiki-plugin.html ==== Changes ==== * 2009-05-04: Original version ===== Syntax ===== Basic statistics can be displayed like this: {{ganalytics>data:}} See available parameters for allowed options for . ==== Parameters ==== A number of parameters can be set by appending them with / character to data parameter. Each parameter needs to be separated with a / character. Defaults for all parameters can be set in the config manager. Below is a list of all recognized parameters and allowed values: ^ Parameter ^ Default ^ Required ^ Allowed Options ^ Description ^ |data: |- |Y |unique, pageviews, visitors, \\ country, countrynewvisitors, browser, \\ resolution, OS, referrers, \\ searchwords, visitortype | Metrics which is displayed: \\ **unique**: Displays a line chart with the unique visitors on your on a day-by-day basis. \\ **pageviews**: Displays a line chart with the pageviews on your on a day-by-day basis. \\ **visitors**: Displays a line chart with the non-unique visitors on your on a day-by-day basis. \\ **country**: Displays a map chart with the location of your visitors for the selected range. \\ **countrynewvisitors**: Displays a map chart with the location of new visitors to your site for the selected range. \\ **browser**: Displays a pie chart with the browser used by your visitors for the selected range. \\ **resolution**: Displays a pie chart with the screen resolution used by your visitors for the selected range. \\ **OS**: Displays a pie chart with the operating system used by your visitors for the selected range. \\ **referrers**: Displays a pie chart with the referrers used by your visitors for the selected range. \\ **searchwords**: Displays a pie chart with the search engine keywords used by your visitors for the selected range. \\ **visitortype**: Displays a pie chart with visitor type for your visitors for the selected range (new visitor or returning visitor). | |linecolor: |000000 |N |[[, hex color], ...] |This parameter has different meanings for different charts: \\ **Line chart**: Color of the line, last value is repeated if there are more lines then colors \\ **Pie chart**: Color of the pie, colors are interpolated if there are more slices then colors \\ **Map chart**: Color of country's, first color is for country's which are not in the dataset, the other colors are interpolated | |bgcolor: |FFFFFF |N | |Background color of the line and pie chart. Color of the water on map charts | |size: |200x200 |N |x |Size of the chart. Best is to make the at least twice as wide as height. | |history: |0 |N | | Selects how many previous months are included in the statistics. Example: setting it to 1 makes a pie chart display statistics of this month and the previous month | |now: |- |N | |Shows a marker on line charts at the current date in color | |continent: |world |N |world, africa, asia, europe, \\ middle_east, south_america, usa |Selects which area is displayed by the map chart | |title: |- |N |<string> |Displays title above chart (not allowed for map charts) | Example: \\ <code>{{ganalytics>data:<metrics>[/linecolor:<linecolor>][/bgcolor:<bgcolor>][/size:<size>][/history:<history>][/now:<now>][/continent:<continent>][/title:<title>]}} {{ganalytics>data:unique/linecolor:007B9F,55A7BF,AAD3DF/size:550x220/history:2/now:FF0000}} {{ganalytics>data:countrynewvisitors/continent:world/size:440x220/linecolor:FFFFFF,FFFFFF,019E18/bgcolor:EAF7FE/history:5}} </code> ===== Additional setting ===== There are a few additional settings in the Configuration Manager: ^Setting ^Description ^ |Google Analytics username |Google analytics username (email) | |Google Analytics password |Google analytics password | |Google Analytics profiel ID |Google analytics profile ID (example ga:12345) | |Show browser version |When selected, the data:browser option shows the browser version. Example Firefox or Firefox 3. | |Show OS version |When selected, the data:osoption shows the OS version. Example Windows or Windows XP. | |Maximum slices for pie chart |The maximum number of slices in a pie chart. The remaining slices are combine as '(other)'. | |Show slice size |When selected, a pie chart shows the size of each slice. Example Windows or Windows (80%) | |Show referral path |When selected, the data:referrs shows the domain and referral path. Example example.com or example.com/dir/. | |3D pie chart |When selected, pie charts are shown in 3D. | |Use simple encoding (only for charts smaller then 300px) |When selected, all data is encoded. This limits both URL size and resolution. | ===== Adding metrics ===== Metrics are added in the following manner: \\ * Have a look at the Google Analytics Data Export API * Add a new function at the bottom of analytics.class.php * Add the new //metric// parameter in the //handle//-function. Adding it to the list of //unique// for a line chart, to //country// for a map chart or to //browser// for a pie chart. * Add the new //metric// parameter in the //render//-function. Same as above. * Add the new //metric// parameter in the //PieChartGetData//-function, //MapChartGetData//-function or //LineChartGetData//-function * Done :-) ===== Demo Installations ===== Here are a few user provided examples of the Google analytics plugin in use: * http://greenbird.info/dokuwiki/ganalytics#demo_installation FIXME (Link is broken.) ===== Discussion===== Ask your questions here. > * May not work on php5 ? ---> I this errors : > "Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /homez.57/momas/www/lib/plugins/ganalytics/syntax.php on line 572" > Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homez.57/momas/www/lib/plugins/ganalytics/analytics.class.php on line 47 >> I'm using PHP Version 5.2.9 and it's working fine. It doesn't work with PHP4 as foreach($array as &$value) is only allowed since PHP5. You can remove this construct by replacing line 569 in syntax.php: <code PHP> function SimpleEncode($array, $max) { $encode = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; foreach ($array as &$value) { if ($value < 0) $value = '_'; else $value = substr($encode, round(((strlen($encode)-1)*$value)/$max), 1); } return $array; } </code> with <code PHP> function SimpleEncode($array, $max) { $encode = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; foreach ($array as $key => $value) { if ($value < 0) $array[$key] = $value = '_'; else $array[$key] = substr($encode, round(((strlen($encode)-1)*$value)/$max), 1); } return $array; } </code> It also uses classes for connecting with the Google analytics server, which also requires, and is supported by, PHP5 or up. >> >Just a question about howto get the param "Google Analytics profiel ID" >> It is simply the ga:+"id" param that appear when you navigate on analytics report: https://www.google.com/analytics/reporting/?reset=1&id=13129515&pdr=20090406-20090506 "Google Analytics profiel ID" = ga:13129515 Thank you for this plugin, have a suggestion: could it be possible to display a list of the most visited pages? for instance: $data = $api->data($id, 'ga:pageTitle,ga:pagePath', 'ga:pageviews',false, date('Y-m-d', strtotime('1 week ago')), false, 15); where "15" and "1 week" should be implemented. ====Monitor two sites==== >I have two sites, and I want to monitor them at the same time. So it will be more useful to make "Google Analytics profile ID" one of the parameter in syntax. For example, %%{{ganalytics>id:12345/data:<metrics>}}%%。I modified the syntax.php to achieve this. First, add the id parameter. That is, change: <code php> switch($parameter){ case 'data': $img['data'] = $value; </code> to <code php> switch($parameter){ case 'id': $img['id']=$value; break; case 'data': $img['data'] = $value; </code> Then, replace <code php> $oAnalytics->setProfileById($this->getconf('ganalytics_id')); </code> with <code php> if(array_key_exists('id', $img)){ $oAnalytics->setProfileById("ga:".$data['id']); } else{ $oAnalytics->setProfileById($this->getconf('ganalytics_id')); } </code>