====== Google Analytics for DokuWiki ====== ---- plugin ---- description: This tool allows you to set a code for use with Google Analytics, which allows you to track your visitors. author : Terence J. Grant email : tjgrant@tatewake.com type : action lastupdate : 2020-11-03 compatible : 2020-07-29 "Hogfather", 2018-04-22 "Greebo", 2017-02-19 "Frusterick Manners", 2016-06-26 "Elenor Of Tsort" depends : conflicts : similar : piwik, referrers tags : google, statistics, embed downloadurl: https://github.com/tatewake/dokuwiki-plugin-googleanalytics/archive/master.zip sourcerepo : https://github.com/tatewake/dokuwiki-plugin-googleanalytics bugtracker : https://github.com/tatewake/dokuwiki-plugin-googleanalytics/issues donationurl: https://www.paypal.com/xclick/business=tjgrant%40tatewake.com&item_name=Google%20Analytics%20for%20DokuWiki%20Donation&no_shipping=1&no_note=1&tax=0¤cy_code=USD&lc=US ---- This plugin allows you to track visits to your wiki in [[https://google.com/analytics|Google Analytics]]. ===== Download ===== Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. ===== Setup ===== This plugin generates JavaScript code that is automatically included into your site via the ''lib/exe/js.php'' file. (Which you can inspect via your browser's "developer tools.") 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.) You may use one of two tracking options: * **Basic** "Google Analytics ID" (also known as "[[https://developers.google.com/analytics/devguides/collection/analyticsjs|analytics.js]]") using a **UA-XXXXXX-XX** code * **Newer** "Global Site Tag ID" (also known as "[[https://developers.google.com/analytics/devguides/collection/gtagjs|gtag.js]]") using a **G-XXXXXXXXXX** code If you set a "Global Site Tag ID", then this method will be used and any "Google Analytics ID" / **UA-XXXXXXX-XX** specific settings will be ignored. ==== Tag Setup ==== To properly use this plugin you will need to set up and configure a Google Analytics property. ==== Google Analytics ID Method ==== Sign into [[https://analytics.google.com]] and create a **new property**: * [[https://support.google.com/analytics/answer/1042508|Analytics Help: Set up a property]] Now follow the steps below. There are also [[http://imgur.com/a/lvhuD|screenshots available]] to help you find your way through the menus. At the end of the setup process you should get a **Tracking Code**. You can also find it under //Admin// -> //Property// -> //Tracking Info// -> //Tracking Code//. The code starts with ''UA'' followed by a large number and a shorter number separated by dashes (''UA-XXXXXX-XX''). Next, setup the **custom dimensions**. Go to //Admin// -> //Property// -> //Custom Definitions// -> //Custom Dimensions//. There create two new custom dimensions: - Name: ''wiki-action'' * Scope: Hit * Index: 1 * Active: yes - Name: ''wiki-id'' * Scope: Hit * Index: 2 * Active: yes Be sure the indexes are correct! Next, if you want to track logged in users across different devices, you have to enable the **User ID tracking** feature and create a new view. To do so go to //Admin// -> //Property// -> //Tracking Info// -> //User-ID// and follow the wizard. Please not that this step is completely optional. It may have repercussions on your privacy policies. Be sure to read the documentation provided by Google. Finally go to //Admin// -> //View// and select the view you want to use((If you set up User ID tracking above, you probably want to repeat this step for both views. Otherwise there's only one)). Then pick //View Settings//. Enable **Site Search Tracking**, enter ''q'' as Query parameter and tick the //Strip query parameters out of URL// checkbox. ==== Global Site ID Method ==== TODO: Write me ==== DokuWiki Setup ==== Once you have finished your Setup at Google Analytics, you can configure DokuWiki. Install the plugin via the extension manager, then go the configuration and use the config options to configure the plugin for your account. You have to fill in at least your Tracking Code! If you enabled User ID tracking in the Google Analytics above, you can enable it here as well. ===== Usage ===== Once configured, your Google Analytics should begin to show data after a day or two. Please refer to [[https://support.google.com/analytics/?hl=en|Google Analytics Help]] for info on general usage. ===== Developer Info ===== Once configured, the plugin makes Google's ''ga()'' method available globally. You can use it to log additional events from your JavaScript. if(window.ga) window.ga('send', 'event', ...); Please refer to Googles documentation on details.