*/
function googleanalytics_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Adds tracking code to all pages of your site');
case 'admin/settings/googleanalytics':
return t('Google Analytics is a free statistics package based on the excellent Urchin system.');
}
}
/**
* Implementation of hook_perm()
*/
function googleanalytics_perm() {
return array('administer googleanalytics');
}
/**
* Implementation of hook_footer() to insert Javascript at the end of the page
*/
function googleanalytics_footer($main = 0) {
global $user;
$id = variable_get('googleanalytics_account', '');
// Check if we should track the currently active user's role
$track = 0;
foreach($user->roles as $role) {
$track += variable_get("googleanalytics_track_{$role}", FALSE);
}
// Don't track page views in the admin sections
if($id && (arg(0) != 'admin') && $track > 0) {
$prefix = '://www';
// Are we on a secure page?
if($_SERVER['HTTPS']) {
$prefix = 's://ssl';
}
return '';
}
}
/**
* Implementation of hook_menu()
*/
function googleanalytics_menu() {
$items[] = array(
'path' => 'admin/settings/googleanalytics',
'title' => 'google analytics',
'callback' => 'googleanalytics_admin',
'access' => user_access('administer googleanalytics'),
'type' => MENU_CALLBACK
);
}
/**
* Implementation of hook_settings() for configuring the module
*/
function googleanalytics_admin() {
$form['account'] = array(
'#type' => 'fieldset',
'#title' => t('Analytics Account Settings'),
'#collapsible' => FALSE,
);
$form['account']['googleanalytics_account'] = array(
'#type' => 'textfield',
'#title' => t('User ID'),
'#default_value' => variable_get('googleanalytics_account','UA-'),
'#size' => 15,
'#maxlength' => 20,
'#required' => TRUE,
'#description' => t('The user account is unique to the websites domain. You can obtain a user account from the %url website.', array('%url' => 'Google Analytics'))
);
// Render the role overview.
$result = db_query('SELECT * FROM {role} ORDER BY name');
$form['roles'] = array(
'#type' => 'fieldset',
'#title' => t('User Role Tracking'),
'#collapsible' => TRUE,
'#description' => t('Define what user roles should be tracked by Google Analytics.')
);
while ($role = db_fetch_object($result)) {
$form['roles']["googleanalytics_track_{$role->name}"] = array(
'#type' => 'checkbox',
'#title' => t($role->name),
'#default_value' => variable_get("googleanalytics_track_{$role->name}", FALSE),
);
}
return system_settings_form('googleanalytics_admin', $form);
}