Skip to content

Google Analytics

Milan Petrovic edited this page Oct 2, 2020 · 3 revisions

Google Analytics

There are so many plugins for implementing Google Analytics, and they get installed on a lot of websites that don't really need them. Most website owners need to insert Google Analytics tracking code, and use all default tracking settings, and make things work without the huge overhead some plugins bring. Many plugins integrate some of the Analytics reports into WordPress administration, but that always is missing some data, so you need to go to the full Analytics website, making the feature unusable. The only way to really analyze the data collected is on the Google Analytics website.

Some of the plugins currently available load tons of JavaScript of their own, slowdown website loading, infest admin side with banners, and messages all over the place. Most of these plugins are too invasive and they really don't do much that is needed by most users. Most users need to enable tracking in Analytics and that's it.

This plugin helps you to insert your Google Analytics tracking code, it inserts tracking code, and you are all set.

Pros to using this plugin

  • Tracking JavaScript code is automatically added to the header of all your website pages
  • By default, is set to anonymized visitor IP's and force use of SSL
  • It loads two tracking features: 'displayfeatures' and 'linkid'
  • It doesn't track super administrator activities (main administrator of the website)
  • It can be expanded with additional snippets for special tracking methods
  • Extremely light-weight with no overhead, just a few lines of code
  • Loads Google Analytics ASYNC version of the script without the use of Tag Manager

Cons to using this plugin

  • It doesn't offer an interface to set up plugin visually
  • It can't connect to Google Analytics, you need to insert the tracking ID
  • Events tracking must be added manually
  • No dashboard integration between Analytics and WordPress website

How this plugin works

The script runs on the frontend only, and by default, it doesn't load for the main website administrator (super admin). Line 24 controls the conditions for inserting the tracking script, so you can expand that if you want with more conditions. And, the core offers 3 filters that you can use to change the condition for display of the tracking script, tracking code, and list of tracking directives.

How to install the plugin

You need a Google Analytics tracking code in format UA-XXXXX-Y. Insert your tracking code into the plugin code on line 18, and replace the placeholder UA-XXXXX-Y with your real tracking code. That's all you need to do.

Add more tracking directives

Plugin code lines 28 to 35 define a list of directives run by the tracking code. You can remove lines you don't need or add more. The first and last directive (lines 29 and 34 are required and should not be removed.