How to add traffic analytics code in WordPress admin dashboard?

There is some popular traffic analyzer available to help you to get the traffic report of your site. To make it work, all you need to do is just copy the analytics code provided by the traffic statistical report providers and paste it on the pages of your site.

Google Analytics, Clicky, StatCounter are some of the popular web traffic analytics code providers. It can help you to know about the traffic state, source of traffic of your website or blog.

Well, WordPress already has several plugins to see the traffic statistics of your site. But here in this post, I am going to tell you how to add traffic analytics code in WordPress admin dashboard.

admin_head action hook

WordPress already has admin_head action hook. Using this hook, you can add anything inside the <head> tag of your WordPress site. If you know how to add any code snippet, content or even comment then you can also add traffic analytics code in WordPress admin dashboard easily.

let’s see how to do that:

function my_traffic_analytics_code() {
  // Add your traffic analytics code here
add_action( 'admin_head', 'my_traffic_analytics_code' );

Inside the function, you have to put the analytics code that you have got from Google Analytics or from any other web analyzer.

For example, if you want to track the traffic for your WordPress admin pages, then below is the code:

function my_traffic_analytics_code() {
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
add_action( 'admin_head', 'my_traffic_analytics_code' );

You can add the above code in the theme’s functions.php file or in a site-wide plugin. You must have to replace the javaScript code into your own traffic tracking code you get from your traffic statistical report provider.


Also, read:


Now you will be able to track and get the traffic report of your WordPress admin dashboard also. You may need to give access to visitors to login and visit WordPress admin dashboard panel. For example, you may have a WordPress blog and you accept guest posting. In that case, users will visit your WordPress dashboard panel to write content.

Now you know how to add traffic analytics code in WordPress admin dashboard.

Leave a Reply

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