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.

By Anand Kumar

I am the person behind this site.


  1. It would be better to register and enqueue the scripts properly, rather than include them in a function.

  2. If I am using Google Tag Manager – how can I insert the GTM code into the body of the wp-login.php file? I’ve tried your code above but it insert it into the head tag. Any help would be appreciated!

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.