Page MenuHomeMiraheze

Special:Analytics showing metawiki stats instead of site-specific stats
Closed, ResolvedPublic

Description

Special:Analytics/MatomoAnalytics on my wiki isn't showing wiki-specific stats, I suspect it's showing universal stats based on what's in the search keywords.

Event Timeline

This is indeed a very strange issue I've never seen before. @Universal_Omega thoughts?

The script has the wrong tracking code for this wiki.

<script type="text/javascript">
	var _paq = window._paq = window._paq || [];
	if ( 1 ) {
		_paq.push(['disableCookies']);
	}
	if ( 0 ) {
		_paq.push(['setRequestMethod', 'GET']);
	}
	_paq.push(['trackPageView']);
	_paq.push(['enableLinkTracking']);
	(function() {
		var u = "https://analytics.wikitide.net/";
		_paq.push(['setTrackerUrl', u+'matomo.php']);
		_paq.push(['setDocumentTitle', "yohajiwiki" + " - " + "Special:Analytics"]);
		_paq.push(['setSiteId', 1]);
		_paq.push(['setCustomVariable', 1, 'userType', "Anonymous", "visit"]);
		if ( 1 ) {
			_paq.push(['addTracker', u + 'matomo.php', 1]);
		}
		var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
		g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
	})();
	</script>

1 is the global tracker.

There must have been an error during wiki creation with Matomo because there is no property for this wiki in Matomo.

OrangeStar subscribed.

https://github.com/miraheze/MatomoAnalytics/blob/970915f877448dc5e07f14fb6399e8259e519379/includes/MatomoAnalytics.php#L196C1-L201C52:

public static function getSiteID( string $dbname, bool $disableCache = false ) {
...
if ( !isset( $id ) || !$id ) {
	$logger->warning( "Could not find {$dbname} in matomo table." );

	// Because the site is not found in the matomo table,
	// we default to a value set in 'MatomoAnalyticsSiteID' which is 1.
	return $config->get( 'MatomoAnalyticsSiteID' );

So that's where MatomoAnalytics is getting the 1. The DB records for MatomoAnalytics are supposed to be populated in https://github.com/miraheze/MatomoAnalytics/blob/970915f877448dc5e07f14fb6399e8259e519379/includes/MatomoAnalyticsHooks.php#L14C1-L16C3 (https://github.com/miraheze/MatomoAnalytics/blob/970915f877448dc5e07f14fb6399e8259e519379/includes/MatomoAnalytics.php#L16). I'll use shell.php to run MatomoAnalyticsHooks::wikiCreation(), which should populate the DB and create this site in Matomo.

I'll use shell.php to run MatomoAnalyticsHooks::wikiCreation(), which should populate the DB and create this site in Matomo.

https://meta.miraheze.org/wiki/Tech:Server_admin_log?diff=prev&oldid=400686

There's another error preventing Special:Analytics from working:

PHP Warning: Undefined array key 0

from /srv/mediawiki/1.41/vendor/oojs/oojs-ui/php/layouts/IndexLayout.php(162)
#0 /srv/mediawiki/1.41/vendor/oojs/oojs-ui/php/layouts/IndexLayout.php(162): MWExceptionHandler::handleError(integer, string, string, integer)
#1 /srv/mediawiki/1.41/extensions/MatomoAnalytics/includes/MatomoAnalyticsOOUIForm.php(67): OOUI\IndexLayout->addTabPanels(array)
#2 /srv/mediawiki/1.41/includes/htmlform/HTMLForm.php(1310): MatomoAnalyticsOOUIForm->getBody()
#3 /srv/mediawiki/1.41/includes/htmlform/HTMLForm.php(1263): HTMLForm->getHTML(boolean)
#4 /srv/mediawiki/1.41/includes/htmlform/HTMLForm.php(652): HTMLForm->displayForm(boolean)
#5 /srv/mediawiki/1.41/extensions/MatomoAnalytics/includes/SpecialAnalytics.php(25): HTMLForm->show()
#6 /srv/mediawiki/1.41/includes/specialpage/SpecialPage.php(727): SpecialAnalytics->execute(NULL)
#7 /srv/mediawiki/1.41/includes/specialpage/SpecialPageFactory.php(1621): MediaWiki\SpecialPage\SpecialPage->run(NULL)
#8 /srv/mediawiki/1.41/includes/MediaWiki.php(357): MediaWiki\SpecialPage\SpecialPageFactory->executePath(string, RequestContext)
#9 /srv/mediawiki/1.41/includes/MediaWiki.php(960): MediaWiki->performRequest()
#10 /srv/mediawiki/1.41/includes/MediaWiki.php(613): MediaWiki->main()
#11 /srv/mediawiki/config/initialise/entrypoints/index.php(100): MediaWiki->run()
#12 /srv/mediawiki/config/initialise/entrypoints/index.php(95): wfIndexMain()
#13 {main}

This is because the wiki was not actually created in Matomo despite Matomo itself giving us a siteID earlier?

OrangeStar removed a project: MatomoAnalytics.

This doesn't seem to be a MatomoAnalytics bug, it seems to be doing everything correctly. The error is either in Matomo or in our Matomo config.

Collei renamed this task from Special:Analytics showing universal stats instead of site-specific stats to Special:Analytics showing metawiki stats instead of site-specific stats.Sat, Jun 8, 06:13
Collei triaged this task as Normal priority.

I'll use shell.php to run MatomoAnalyticsHooks::wikiCreation(), which should populate the DB and create this site in Matomo.

Appears to be fixed now, possibly because of this?