How to Track WordPress Login, Register and Dashboard Activity with Google Analytics

If you have a multi-author blog or a forum or some membership site based on WordPress. Then, you might like to add Google Analytics to WordPress Login, Register or even dashboard. It will help you to understand better about your users’ requirement and help you to how they are using your site.

Google Analytics on WordPress

Another good thing about this article is there is no need of any plugin. And we can easily add Google Analytics to WordPress Login and Register pages or even WordPress Dashboard. Now proceed to next.

If you are using a site specific plugin then add the following code to the plugin else add these codes to your active theme (or child theme) functions file. If you are absolute beginner then you may locate these files here.

Go to WordPress Dashboard –> Appearance –> Editor –> Theme Functions (functions.php)

Add Google Analytics code to WordPress login and register page

This is really easy, simply copy the following code and replace the line <!-- Your Analytics Code Here --> with your actual Google analytics tracking code.

add_action( 'login_head', 'synt_ga_login_page');
function synt_ga_login_page() { ?>
    <!-- Your Analytics Code Here -->
<?php }

This will add your analytics code to WordPress login, register and forget password page.

Track WordPress Dashboard with Google Analytics

Also, If you want to track WordPress Dashboard activities then add the following code.

add_action( 'admin_head', 'synth_admin_head_script' );
function synth_admin_head_script() {
  if ( !is_super_admin() || !is_admin() ) { ?>
    <!-- Your Analytics Code Here -->
 <?php } }

As you see, there is a if condition in the code snippet. If will filter super admins and admin of your WordPress. You may also customize users based on their roles and capabilities.

If you are going to make any change in the above code (other than adding google analytics code) then test your code on a test server. Otherwise, it may potentially break your site.

If you have any problem or have any suggestion leave a comment below. If you liked this article, please share with your friends.

How to add Google Analytics to WordPress sites


Google Analytics is a fabulous analytics tool enabled on more than 10 million websites across the globe. Here we will add Google Analytics to WordPress site. Obviously, we will need a Google Account first. Here I will skip this because most of us already have a GMail or Adsense Account or even an account associated to Android Phone. So going to straight to Google Analytics Sign up page.

Important: If you do not have Google account and Google is forcing you to create an email id. Then you may directly go to and start signup process for Google Analytics with your existing email address. You may also use your Google Apps account to sign up Analytics.

Sign Up Google Analytics Account:

Once you have logged in to Google Account you may sign up Google Analytics account. The Analytics signup page will be something like this. Add account name, site name, website url, industry category and time-zone for your reporting. Don’t worry about any discrepancy, you may change all these information later.


After filling the information required proceed to accept terms of the services and sign up. If everything goes right you will get your tracking code and Google Analytics account instantly. Your Analytics account id will be something like “UA-47713692-1” and some JavaScript code something like below. Some WordPress themes including thesis theme framework have built-in functionality where we have to enter the tracking id only. For rest of the themes we will need the entire script.


Adding Google Analytics code to WordPress site:

Once we have Google Analytics code we will now add this tracking code to the WordPress site. There are a few approaches to do that.

  1. Add the code using wp_head or wp_footer hook.
  2. Directly add the code to theme file (by modifying header.php or footer.php)
  3. Using a plugin or theme feature

Add the code using wp_head or wp_footer hook.

You may add a few lines of code to theme’s functions.php  file.

* How to add Google Analytics to WordPress by @_Anand_Kumar
* Tutorial link
add_action( 'wp_head', 'synth_google_analytics');
function synth_google_analytics() { ?>
<?php }

Do not forget to replace <!-- REPLACE THIS LINE WITH GOOGLE ANALYTICS CODE --> with your actual Google analytics code.

That’s all. Your WordPress site will, now, be tracked by Google Analytics.

Directly add the code to theme file (by modifying header.php or footer.php)

You may copy and place the obtained code to header.php file. Here, we will have to find the closing head tag ie </head>. Once you find the code place the Analytics code just above it.

This method is do not works will all themes because many themes do not have header.php or the theme developer do not suggest to modify the code directly to theme file.

Add Google Analytics to WordPress using theme feature / option.

A lot of themes (including Genesis, Thesis) have options to hook some code to header and/or footer. You may use this feature. This is one of the easy (and safe) way to add scripts to your sites.

  • Genesis user may add the code to “Header and Footer script” under Genesis Setting menu.
  • Thesis 2 user may navigate to Thesis >> Site >> Google Analytics (just place the id, which will be like UA-123456-1. See the highlighted image 2) OR add the whole tracking code under Thesis >> Site >> Tracking Script.
  • There are a few plugin who offers some features add the code at ease.

Now if you might ask which method I prefer! Frankly I will prefer either method one or three (if my theme has such feature.)

Here are a few reasons behind it.

  • Using a plugin for everything sucks. It will slow down the speed of your site and ultimately provide bad user experience.
  • If the theme has such functionality then we may add a number of scripts using just one hook.
  • Modifying Theme file will be hard to maintain at some point in future.
  • An intermediate (or even you) may opt for a site specific plugin. This will be best option to add cross theme functionally. Here you may find more information about site specific plugin. Note: Any of the above three method will be enough for this purpose.
  • I like adding the Google Analytics code to WordPress Head because it provides more accurate analytics. While some blogger add the code at the end of the body tag. Read this article for details.

I this article helped you don’t forget to share with your friends. Your every tweet, fb like or +1 will help this site grow. So, help us if you liked. If you have any problem or suggestion leave a comment below.