Google Analytics is a wonderful tool for tracking how people interact with your website.
You sign up for Google Analytics and they give you a code snippet which you install on every page you want to track. The code snippet remains the same for an entire “property.”
Create a property for each unique website.
Put the code in one centralized location and reference it on pages. Google periodically changes their code, so you don't want to have to change it in multiple places when they upgrade.
Create a file “analytics.js” and place the code snippet inside.
Upload that to your webserver.
Make sure to remove the <script> and </script> tags.
It should look like this:
ga('create', 'UA-XXXXXXXX-1', 'auto');
There are a lot of tutorials that tell you to insert the code into a skin, but what if a user changes skins? What if you get tired of your skin? That method is stupid.
Open Common.js by going to: /YourWiki/index.php?title=MediaWiki:Common.js
Edit the page to add: