Topic on Project:Support desk

How to get Piwik code into MobileFrontend?

17
MadenssContinued (talkcontribs)

I use the Piwik Integration extension, but the Piwik code doesn't make its way into mobile view of the site.

What can I change to accomplish this?

MarkAHershberger (talkcontribs)

It looks like the Piwik extension uses the Hooks/SkinAfterBottomScripts hook to inject itself and the mobile skin doesn't call the function that calls that hook.

It looks like the clue is here:

// TODO and the suckage continues. This function is really just a wrapper around
// OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
// up at some point
MarkAHershberger (talkcontribs)
MadenssContinued (talkcontribs)

Thanks for that. Can you suggest a place that I could paste the Piwik code into so I can get reports for mobile users?

MarkAHershberger (talkcontribs)

You could put the code in your site's [[MediaWiki:Common.js]] and that would be used for both mobile and regular interfaces. Make sure $wgUseSiteJs is true, though.

If/when the bug gets fixed, though, you'll want to remove the code from your Common.js, of course.

MadenssContinued (talkcontribs)

I commented out the plugin related entries in LocalSettings.php. I then added the Piwik code from the Piwik dashboard to MediaWiki:Common.js and set $wgUseSiteJs = true in LocalSettings.php.

Loading my site with this configuration gives error 500 internal server error. Commenting out the $wgUseSiteJs statement returns the server to normal.

I tried copying only the javascript itself (not that tags around it) and got the same error. I'm not sure how to set this configuration.

MarkAHershberger (talkcontribs)

Is there a semicolon at the end of $wgUseSiteJS = true? Like this:

 $wgUseSiteJS = true;

If you leave it un-commented, but change it to false instead of true does the error disappear?

Could you give me the URL to your site?

What version of MediaWiki are you using?

Which extensions do you have installed?

MadenssContinued (talkcontribs)

Geez, I did forget the semicolon.

www.unpm.org/wiki

Mediawiki 1.22.2

Cite SyntaxHighlight MobileFrontend

The contents of Mediawiki:Common.js do not show up in page source with $wgUseSiteJS = true;.

MadenssContinued (talkcontribs)

Well, nevermind. Somehow the script loads without appearing in page source. I can see Piwik tracking me on the site, but I can't see the script in the page source. It does track when using Mobile View, as well.

There is a <noscript> code to use for image tracking when users browse a site without javascript. Will that load if I put it in MediaWiki:Common.js?

Ricordisamoa (talkcontribs)

Not at all. But you could put it into MediaWiki:Sitenotice instead (not sure if it works).

MadenssContinued (talkcontribs)

Putting it in MediaWiki:Sitenotice did not work. It just displayed the text, including tags, at the top of every page in the wiki.

Ricordisamoa (talkcontribs)

Then it is probably in raw HTML, which is not allowed in MediaWiki by default (enabling raw HTML would raise security issues). So it should be inserted server-side.

MadenssContinued (talkcontribs)

Which file would I edit (I administrate the server)?

MarkAHershberger (talkcontribs)

Use the SkinAfterBottomScripts hook to add it. You can do this by using something like the following (untested) code:

$wgHooks['SkinAfterBottomScripts'][] =
 function ($skin, &$text) {
   $text .= "<script><!-- js you want --></script>";
 };
MarkAHershberger (talkcontribs)

That should be added to your LocalSettings.php.

134.53.245.65 (talkcontribs)

I found this thread while trying to fix the same problem. I have no real experience with websites, so I'm having a little difficulty following along. Where can I find the MediWiki:Common.js file mentioned above?

MadenssContinued (talkcontribs)

It is a MediaWiki configuration page:

http://www.example.com/wiki/MediaWiki:Common.js

Reply to "How to get Piwik code into MobileFrontend?"