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: 766

Si te gustó/sirvió puedes invitarme a unos cafés aquí (desde 1€). ¡Los tomaré a tu salud! ¡Gracias!

.........Puedes donar con Paypal, tarjeta o transferencia.........
(Es pago seguro)

Si te ha gustado este blog, SUSCRÍBETE aquí (tan solo tienes que anotar tu email).
Te llegará un aviso cada vez que publique nuevos artículos.

Para que te llegue un email cada vez que escribo un nuevo post inscríbete pinchando en este sobre naranja

Angel Abril-Ruiz

¡Hola! Algunos dicen que tengo una inquietud cognitiva un tanto dispersa, y creo que razón no les falta 😅. Empecé mi carrera profesional como Ingeniero de Telecomunicación 📡(UPV). Luego me dediqué al mundo de la gestión y el marketing 📊 (Ciencias Empresariales, UCM; Master in Management, IE Business School). Tras trabajar varios años en una multinacional y fundar algunas empresas entré en el mundo de la investigación científica en ciencias del comportamiento 🧠 (Master Ciencias de la Empresa y Doctorando, UMU; Grado en Psicología, UNED). Últimamente fluyo en las disciplinas de Behavioral Sciences, Sustainable Behavior, Social Psychology, Consumer Psychology and Energy Saving. También hago bizcochos, pan de masa madre y siembro hortalizas en un huerto 🍆🥦. Mi lado más personal lo puedes encontrar aquí y en Youtube 🎥: http://www.youtube.com/aabrilru . Enjoy! 🤗

View more posts from this author

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *