I made a mod based on the 1.1 version.
I add the possibility to add a user variable readable by Google Analytics which allow to segment logged in user or to filter users logged in manager. With this plugin, just add a filter to delete you developpement traffic to you statistics or consult the "All Reports" -> "Merketing optimisation" -> "Visitor Segment Performance" -> "User-defined" page to see the segmentation.
// <?php
// Google Analytics Plugin by Mark Kaplan moded by Oncleben31
// 15-Oct-2006
// version 1.1+ (based on 1.1)
//
// Adds your Google Analytics to every page in your site
// The mod allows to add a variable to filter and/or segment visitor according there are logged in,
// manager user or simple users. Essential to optimize you logs or to filter the developpement traffic on you site.
//
// Parameter: &account=Account;string;UA-000000-0 &filterManager= Filter Manager User;list;Yes,No;No &userGroupSegment=User Groups segmenting;list;Yes,No;No
// Event: OnWebPagePrerender
$e = $modx->Event;
$account = isset($account)? $account: '';
$filterManagerFlag = isset($filterManager)? (($filterManager=='Yes')? 1: 0): 0;
$userGroupSegmentFlag = isset($userGroupSegment)? (($userGroupSegment=='Yes')? 1: 0): 0;
$userName = $modx->getLoginUserName();
$script = $account? '
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "'.$account.'";
urchinTracker();
</script>
': '
<!-- Google Analytics Account Not Supplied -->
';
switch ($e->name) {
case "OnWebPagePrerender":
$googleize = ($modx->documentObject['donthit']==0 && $modx->documentObject['contentType']=='text/html');
if ($googleize) {
$modx->documentOutput = preg_replace("/(<\/body>)/i", $script."\n\\1", $modx->documentOutput);
// Filter users logged in Manager
if($filterManagerFlag && isset($_SESSION['mgrValidated']) && $_SESSION['mgrValidated']) {
$bodyScript = 'onLoad="javascript:__utmSetVar(\'admin_user\')"';
$modx->documentOutput = preg_replace("/(<body)/i", "\\1 ".$bodyScript, $modx->documentOutput);
}
// Filter users logged in Manager
elseif($userGroupSegmentFlag && $userName) {
$bodyScript = 'onLoad="javascript:__utmSetVar(\'logged_user\')"';
$modx->documentOutput = preg_replace("/(<body)/i", "\\1 ".$bodyScript, $modx->documentOutput);
}
}
break;
default :
return; // stop here - this is very important.
break;
}
// ?>
Can you check the code because I’m not a master in PHP and in RegExp. I’m not sur to cover all the possibility with the modification of the <body> tag.