• [ Moderator note: moved to Fixing WordPress. Please do not use Developing with WordPress for these topics. ]

    Hi,

    I would like to implement Google Analytics on my wordpress site and want to exclude all internal traffic, to do this I need to add a Google Analytics code to a page that only internal users visit. So every user that visit that particular page won’t be counted in Google Analytics.
    So the best spot to add this would be according to me the “Dashboard” of WordPress.
    Can somebody give me an idea where and how I could add this and if this addin would be lost if it update WordPress?

    The code would look something like this:
    <!– Google Analytics –>
    <script>
    (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

    ga(‘create’, ‘UA-XXXXX-Y’, ‘auto’);
    ga(‘send’, ‘pageview’, {
    ‘dimension1’: ‘internal’
    });
    </script>
    <!– End Google Analytics –>

    Thanks for the help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey @airwolfke,

    You can use any of these action hooks, depending on your preference for whether this code is added in the header or footer and whether it’s loaded before or after default scripts:

    • admin_print_scripts
    • admin_head
    • admin_footer
    • admin_print_footer_scripts

    Here’s an example of how to add your GA code using the admin_footer action hook:

    
    add_action( 'admin_footer', 'airwolfke_google_analytics_internal' );
    function airwolfke_google_analytics_internal() {
         ?>
    	<!– Google Analytics –>
    	<script>
    	(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
    	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    	})(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);
    
    	ga(‘create’, ‘UA-XXXXX-Y’, ‘auto’);
    	ga(‘send’, ‘pageview’, {
    	‘dimension1’: ‘internal’
    	});
    	</script>
    	<!– End Google Analytics –>
         <?php
    }
    

    You could add this code to the functions.php of your active theme. If you’re using a third-party theme, you’ll want to add this to a child theme instead of modifying the third-party theme to ensure the code is not lost if/when the theme is updated.

    You could also add this code to a custom plugin, which is preferable in this case as the code is not specific to your theme.

    That said, if you’re already using any decent plugin to add your Google Analytics code to the site, it should include an option to exclude the tracking code for specific users by role, making the above unnecessary.

    Hope that helps!

    Hello,
    I am using Magazine plus by WEN Themes free version. Its look good and i establish my website on it. But now i am facing a problem my google analytics code and adsense code not running in this theme. I am new and its my 1st website so anybody please guide me. I also gave msg to wen theme but no response getting form their side. someone suggest me wordpress support will give you fully help so i am here.

    please revert as soon as possible

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Implementing Google Analytics BACKEND’ is closed to new replies.