Location: PHPKode > projects > ProjectPress > projectpress/pm-content/plugins/google-analytics.php
Plugin Name: Google Analytics
Plugin URI: http://www.7mediaws.org/
Version: 1.0
Description: A simple plugin to add Google Analytics code to the footer of all your pages. Simply enter your ID on the options page and you're ready to go.
Author: Joshua Parker
Author URI: http://www.joshparker.us/

// Register our plugin admin page
add_action( 'plugins_loaded', 'google_analytics_page', 10 );

function google_analytics_page() {
// parameters: page slug, page title, and function that will display the page itself
register_plugin_page( 'google_analytics', 'Google Analytics Settings', 'google_analytics_do_page' );

// Display Google Analytics Settings page
function google_analytics_do_page() {
	// Check if a form was submitted
	if( isset( $_POST['submit'] ) )

				<div id="page-title">
					<img src="<?php _e(PM_URI); ?>/images/cog.png" alt="" /><h1><?php _e('Google Analytics Settings'); ?></h1>
		<div id="middle">
			<table cellspacing="5" cellpadding="0">
				<form name="options" method="post">
					<tr><td><?php _e('Google Analytics Code:'); ?></td> <td><input class="forminput" name="google_analytics" size="40" value="<?php echo get_pm_option('google_analytics'); ?>" maxlength="255"></td></tr>
					<tr><td></td> <td><input type="submit" id="sub_button" name="submit" value="Update"></td>


// Update option in database
function update_google_option() {
	$google_analytics = $_POST['google_analytics'];
	// Update value in database
	update_pm_option( 'google_analytics', $google_analytics);
	header('Location: plugins.php?page=' . $_GET['page']);

function google_analytics() {
	echo "<script type=\"text/javascript\">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '" . get_pm_option('google_analytics') . "']);

  (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);

Return current item: ProjectPress