Skip to content

Commit

Permalink
Merge commit 'ad2591c52963ceb02bfdb2001ee75ba7a1e581eb'
Browse files Browse the repository at this point in the history
* commit 'ad2591c52963ceb02bfdb2001ee75ba7a1e581eb':
  Add feature to track user name

Conflicts:
	Piwik.php

fixing #10
  • Loading branch information
DaSchTour committed May 7, 2014
2 parents 42f5302 + ad2591c commit 2d038aa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
21 changes: 19 additions & 2 deletions Piwik.hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public static function AddPiwik ($title) {
global $wgPiwikIDSite, $wgPiwikURL, $wgPiwikIgnoreSysops,
$wgPiwikIgnoreBots, $wgUser, $wgScriptPath,
$wgPiwikCustomJS, $wgPiwikActionName, $wgPiwikUsePageTitle,
$wgPiwikDisableCookies, $wgPiwikProtocol;
$wgPiwikDisableCookies, $wgPiwikProtocol,
$wgPiwikUsernameCustomVariable, $wgUser;

// Is piwik disabled for bots?
if ( $wgUser->isAllowed( 'bot' ) && $wgPiwikIgnoreBots ) {
Expand Down Expand Up @@ -76,7 +77,23 @@ public static function AddPiwik ($title) {

// Contents are empty
} else $customJs = null;


// Set a custom variable for the user name if it's been configured for
// the extension and the user is logged in. The user name for
// anonymous visitors is their IP address which Piwik already records.
if (!empty($wgPiwikUsernameCustomVariable) &&
is_array($wgPiwikUsernameCustomVariable) &&
count($wgPiwikUsernameCustomVariable) == 2 &&
$wgUser->isLoggedIn()) {

$index = $wgPiwikUsernameCustomVariable[0];
$name = $wgPiwikUsernameCustomVariable[1];

$username = $wgUser->getName();

$customJs .= PHP_EOL . " _paq.push(['setCustomVariable',{$index},'{$name}','{$username}']);";
}

// Check if server uses https
if ($wgPiwikProtocol == 'auto') {

Expand Down
1 change: 1 addition & 0 deletions Piwik.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@
$GLOBALS['wgPiwikActionName'] = "";
$GLOBALS['wgPiwikDisableCookies'] = false;
$GLOBALS['wgPiwikProtocol'] = 'auto';
$GLOBALS['wgPiwikUsernameCustomVariable'] = array();

11 changes: 10 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,13 @@ Custom variables

* In case you want to include the title as, for example,
"wiki/Title of the page", you can set ```$wgPiwikUsePageTitle``` to
```true``` and set ```$wgPiwikActionName``` to ```wiki/```. The extension will print piwik_action_name = 'wiki/Title of the page';
```true``` and set ```$wgPiwikActionName``` to ```wiki/```. The extension will print piwik_action_name = 'wiki/Title of the page';

* If you want to track the username of the visitor, set the
```$wgPiwikUsernameCustomVariable``` array variable inside
LocalSettings.php. The array must have two indexes: the first to specify the
index, number from 1 to 5, where this custom variable name is stored in
Piwik; and second for the name of the custom variable in Piwik. For example,
to set the the first custom variable spot in Piwik and have it show up as
"User":
> ```$wgPiwikUsernameCustomVariable = array(1, 'User');```

0 comments on commit 2d038aa

Please sign in to comment.