Created
November 7, 2012 00:34
-
-
Save juanramon/4028727 to your computer and use it in GitHub Desktop.
Google Analytics for GlotPress Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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