Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track 404 Not Found errors for page that don't exist #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace MediaWiki\Extension\Matomo;

use RequestContext;
use Skin;
use Title;
use Xml;

class Hooks {
Expand All @@ -19,7 +21,7 @@ class Hooks {
/**
* Initialize the Matomo hook
*
* @param string $skin
* @param Skin $skin
* @param string &$text
* @return bool
*/
Expand Down Expand Up @@ -77,7 +79,7 @@ public static function onSpecialSearchSetupEngine( $search, $profile, $engine )

/**
* Add Matomo script
* @param string $title
* @param Title $title
* @return string
*/
public static function addMatomo( $title ) {
Expand Down Expand Up @@ -185,6 +187,15 @@ public static function addMatomo( $title ) {

}

$track404s = '';
if ( !$title->exists() ) {
$track404s = "_paq.push(["
. "'setDocumentTitle',"
. "'404/URL = ' + encodeURIComponent(document.location.pathname+document.location.search)"
. " + '/From = ' + encodeURIComponent(document.referrer)"
. "]);";
}

// Prevent XSS
$finalActionName = Xml::encodeJsVar( $finalActionName );

Expand All @@ -205,6 +216,7 @@ public static function addMatomo( $title ) {
<!-- Matomo -->
<script type="text/javascript">
var _paq = _paq || [];{$disableCookiesStr}{$customJs}
{$track404s}
_paq.push(["{$trackingType}"{$jsTrackingSearch}]);
_paq.push(["enableLinkTracking"]);

Expand Down