Etiqueta: adsense

How to add Google adsense and analytics code to Mediawiki

How to include analytics (GA4), adsense or another code on Mediawiki (1.35 or upper)

Hi friends!

This weekend I’ve been trying to tidy my webpages. One of the things that I’ve pending for a long time was to update the wikis that I have in production (bulidomics.com/wiki, neuromarkewiki). I had the version 1.26.2 (cycle of life until 2017) and I wanted to upgrade to 1.39.x (the last LTS version).

The process to upgrade is easier than I thought but I found problems with some extensions, for example, integrating the new GA4 Google Analytics Code and the code for Google adsense.

Google Analytics Code and Google Adsense Code

I have to say that I’m not a professional programmer and maybe there’s another better solution, but the next option I’m going to share works for me.

We know that we have a extension that allows to include the typical Google analytics code until july 2023, the Universal Analytics (UA code), but a few months ago Google has changed the system migrating to his new GA4. Nowadays, the code and the script are different and the wiki extension that we used doesn’t work (I think).

I was finding the way to modify the code that builds the final html shown on the browser. In the 1.26.2 version the .php file in charge of doing it is located in the skin folder, the Vector.php file (if you are using the Vector skin). This is what I did when I installed the wikis for first time; the next screenshot shows the code I added in the 1.26.2 version:

Including script code en MediaWiki 1.26.2

Including script code en MediaWiki 1.26.2

 

But the structure of the skin is different in the new 1.39.x version. In this version, we don’t have a Vector.php. But I’ve found the file Footer.mustache to do something similar. This file is on > ‘w/skins/Vector/includes/templates/Footer.mustache’.

If you edit this file, what you write beetwen <footer> and </footer> will be showed at the footer of every page of the site.

How to add Google adsense and analytics code to Mediawiki

How to add Google adsense and analytics code to Mediawiki

 

I’ve not found how to insert the code in the header, so, if you know how to do it, please tell me! 🙂

Maybe there’s another solution (I’m sure!) but I’ve not found it.

Defenitely, writing the code in this part of the ‘Footer.mustache’ file, you’ll achieve to insert it in each page of your wiki —if you are using the Vector skin.

I hope this tip will be useful for you (and for me ‘future me’ 🙂 ).

Abrazos y abrazas.
A.

Hits: 1075