function getclicky_footer in Clicky - Web Analytics in Real Time 5
Same name and namespace in other branches
- 6 getclicky.module \getclicky_footer()
Implementation of hook_footer() to insert Javascript at the end of the page
File
- ./
getclicky.module, line 39
Code
function getclicky_footer($main = 0) {
global $user;
$id = variable_get('getclicky_account', '');
// Check if we should track the currently active user's role
$track = _getclicky_track($user);
// Don't track page views in the admin sections
if ($id && arg(0) != 'admin' && $track == TRUE) {
$prefix = '://www';
// Are we on a secure page?
if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') {
$prefix = 's://ssl';
}
// Add User profile segmentation values
if (is_array($profile_fields = variable_get('getclicky_segmentation', '')) && $user->uid > 0) {
$p = module_invoke('profile', 'load_profile', $user);
$fields = array();
foreach ($profile_fields as $field => $title) {
$value = $user->{$field};
if (is_array($value)) {
$value = implode(',', $value);
}
$fields[$field] = $value;
}
// Only show segmentation variable if there are specified fields.
$segmentation = '';
if (count($fields) > 0) {
$segmentation = drupal_to_js(implode(':', $fields));
}
}
// Download tracking
$path = drupal_get_path('module', 'getclicky');
// Add any custom code snippets if specified
$codesnippet = variable_get('getclicky_codesnippet', '');
// Site search tracking support.
$url_custom = '';
if (module_exists('search') && variable_get('getclicky_site_search', FALSE) && arg(0) == 'search') {
$keys = search_get_keys();
$url_custom = url('search/' . arg(1), 'search=' . trim($keys));
}
// Surround custom urls with single quotes.
if (!empty($url_custom)) {
$url_custom = drupal_to_js($url_custom);
}
$getclicky_account = variable_get('getclicky_account', '');
$getclicky_db = variable_get('getclicky_db', '');
if (variable_get('getclicky_image', FALSE)) {
$script = '<a title="Clicky Web Analytics" href="http://getclicky.com/' . $getclicky_account . '"><img alt="Clicky Web Analytics" src="http://static.getclicky.com/media/links/badge.gif" border="0" /></a>';
$script .= '<script src="http://static.getclicky.com/' . $getclicky_account . '.js" type="text/javascript"></script>';
$script .= '<noscript><img alt="Clicky" src="http://in.getclicky.com/' . $getclicky_account . '-db4.gif" /></noscript>';
$script .= '<script type="text/javascript">';
if (!empty($codesnippet)) {
$script .= $codesnippet;
}
$script .= '</script>';
}
else {
$script = '<script src="http://static.getclicky.com/' . $getclicky_account . '.js" type="text/javascript"></script>';
$script .= '<noscript><img alt="Clicky" src="http://in.getclicky.com/' . $getclicky_account . '-db4.gif" /></noscript>';
$script .= '<script type="text/javascript">';
if (!empty($codesnippet)) {
$script .= $codesnippet;
}
$script .= '</script>';
}
return $script;
}
}