Snippets

Jones Cropper Google Analytics PageView Tracker

Created by Jones Cropper last modified
<?php
/*
Plugin Name: Google Analytics PageView Tracker
Description: Automatically add tracking code for Google Analytics to each page view by inserting the tracking script into the head tag.
Version: 1.0
Author: Jones S. Cropper
Author URI: http://www.callowcreation.com
Plugin URI: https://bitbucket.org/snippets/caLLowCreation/8KprR/google-analytics-pageview-tracker
License: GPL3
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
*/

function wp_google_site_tracker() { ?>

<!-- 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-XXXXXXXX-X', 'auto');
	  ga('send', 'pageview');

	</script>
<!-- End Google Analytics -->

<?php }

add_action('wp_head', 'wp_google_site_tracker');

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.