LP Devs Blog

Simple Google Analytics plugin for Wordpress

Posted on April 03, 2017

Create Google Analytics account overview

  • Google Analytics Solutions offer free and enterprise analytics tools to measure website, app, digital and offline data to gain customer insights.
  • To use Google Analytics, you have to sign up for Google Account, then using it to sign in Google Analytics.
  • Create an account, then make a property as a web application. You will have a ID for each application, example: UA-96583605-1. Then just use it below.

Code for Plugin

  • Code:
      // Plugin Name: Simple Google Analytics Plugin for Wordpress
      // Description: Adds a Google analytics tracking code to the <head> of your theme, by hooking to wp_head.
      // Author: LP Devs
      // Version: 1.0
      function wp_lpdevs_google_analytics() {
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        ga('create', 'Google-Analytics-ID', 'auto');
        ga('send', 'pageview');
      add_action( 'wp_head', 'wp_lpdevs_google_analytics');
  • Replace Google-Analytics-ID with yours, such as: UA-96583605-1

How to use

  • Copy this file to /wp-content/plugins
  • After that, login to Wordpress Dashboard, choose Plugin. You will see this new plugin is listed. Just activate it.

This is a simple google analytics plugin for wordpress. And I use it for all of my websites. I hope it is helpful for you. If you have some questions, feel free to ask me.

Thanks, LP Devs


Categories: Wordpress
Tags: Plugin Wordpress | Google Analytics