Adding Google Analytics to a Wiki

From apimba
Revision as of 18:02, 22 March 2022 by Milllo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I tried following the mediawiki instructions for adding google analytics to my wiki but they did not work. After much trial and error, the following procedure was found to work fine:

  1. Assume that a google analytics account is already set up and functioning for the standard html web page fronting your wiki and that the headscript extension is installed for your wiki software.
  2. Log into Google Analytics
  3. On the left side tab menu, lower corner, click the “Admin” button
  4. In the second column of the Admin menu, Click “Data Streams”
  5. Click the “>” at the end of the line for your stream
  6. In the “Tagging Instructions” section of the menu, expand the “Global site tag (gtag.js)” option
  7. Copy the text in the window and place it in your LocalSettings.php file for your wiki. The text will be similar to below, where G-01NDZHCJMM is a user specific code so yours will be different (In other words, do not use G-01NDZHCJMM)

<script async src="https://www.googletagmanager.com/gtag/js?id=G-01NDZHCJMM"></script>

<script>

window.dataLayer = window.dataLayer || [ ];

function gtag(){dataLayer.push(arguments);}

gtag('js', new Date());

gtag('config', 'G-01NDZHCJMM');

</script>

  1. Check that the text is showing up on your wiki pages by right clicking a page and select "view page source". The text should be in the <head> section of the web page.
  2. Wait a few days for data to appear on your analytics page.