diff --git a/action.php b/action.php index 7587121..8ba36f8 100644 --- a/action.php +++ b/action.php @@ -34,7 +34,7 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin { // is there a user logged in? $username = ( !empty($INFO['userinfo']) && !empty($INFO['userinfo']['name']) - ? $INFO['userinfo']['name'] : null); + ? $INFO['userinfo']['name'] : ''); // build the tracker code: $code = NL . DOKU_TAB . "document._botmon = {'t0': Date.now()};" . NL; @@ -56,9 +56,13 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin { /* Write out server-side info to a server log: */ // what is the session identifier? - $sessionId = $_COOKIE['DokuWiki'] ?? null; - $sessionType = 'dw'; - if (!$sessionId) { + $sessionId = $username; + $sessionType = 'usr'; + if ($sessionId == '') { + $sessionId = $_COOKIE['DokuWiki'] ?? ''; + $sessionType = 'dw'; + } + if ($sessionId == '') { $sessionId = $_SERVER['REMOTE_ADDR'] ?? ''; if ($sessionId == '127.0.0.1' || $sessionId == '::1') { $sessionId = 'localhost'; diff --git a/client.js b/client.js index d3dc770..8402037 100644 --- a/client.js +++ b/client.js @@ -54,9 +54,11 @@ botmon_client = { _onHeartbeat: async function(url) { //console.info('botmon_client._onHeartbeat', url); + let uid = document._botmon.user || null; + try { - const response = await fetch(url + '?p=' + encodeURIComponent(JSINFO.id) + '&t=' + Date.now(), { - //method: 'HEAD', + const response = await fetch(url + '?p=' + encodeURIComponent(JSINFO.id) + '&t=' + Date.now() + ( uid ? '&u=' + encodeURIComponent(uid) : ''), { + method: 'HEAD' }); if (!response.ok) { throw new Error(response.status + ' ' + response.statusText + ' - ' + url); diff --git a/pview.php b/pview.php index bf864d5..0ed3f3b 100644 --- a/pview.php +++ b/pview.php @@ -8,9 +8,13 @@ if (!$json) { } // what is the session identifier? -$sessionId = $_COOKIE['DokuWiki'] ?? null; -$sessionType = 'dw'; -if (!$sessionId) { +$sessionId = $json['u'] ?? ''; +$sessionType = 'usr'; +if ($sessionId == '') { + $sessionId = $_COOKIE['DokuWiki'] ?? ''; + $sessionType = 'dw'; +} +if ($sessionId == '') { $sessionId = $_SERVER['REMOTE_ADDR'] ?? ''; if ($sessionId == '127.0.0.1' || $sessionId == '::1') { $sessionId = 'localhost'; diff --git a/tick.php b/tick.php index ee92462..fe11038 100644 --- a/tick.php +++ b/tick.php @@ -1,17 +1,18 @@