Skip to content

Instantly share code, notes, and snippets.

@juanramon
Created November 7, 2012 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanramon/4028727 to your computer and use it in GitHub Desktop.
Save juanramon/4028727 to your computer and use it in GitHub Desktop.
Google Analytics for GlotPress Plugin
<?php
class Google_Analytics extends GP_Plugin {
var $ga_id;
function __construct() {
parent::__construct();
$this->add_action( 'gp_footer' );
$this->ga_id= 'YOUR_GA_TRACKING_ID';
}
function gp_footer() {
$footer = <<<FOOTER
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '$this->ga_id']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
FOOTER;
echo $footer;
}
}
GP::$plugins->google_analytics = new Google_Analytics;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment