Topic: [Plugin] Google Analytics  (Read 7779 times)

Pages: 1 [2]  All   Go Down

#21: 24-Jun-2006, 07:55 AM

copernic67
Posts: 1

lejoe

I just installed this plugins and wanted to share the problem i had at the install... perhaps it can help someone.

it too me 3h to find those two points:
  • I had to replace $modx->documentContent by $modx->documentOutput
  • When i copy pasted the plugin code, the "<?php" and "?>" where in my copy so the plugin wasn't working...

But finally works...

And also replaced the preg_replace to put the script before the body and not any more after the head end tag. According to the new google analytics directives:

http://www.google.com/support/analytics/bin/answer.py?answer=26908&topic=7174

So here is my code version:

Code:
// Google Analytics Plugin by Mark Kaplan
// 31-Jan-2006
// version 1.0
// Modified by lejoe 24-Jun-2006
//
// Adds your Google Analytics to every page in your site
//
// Parameter: &account=Account;string;UA-00000-0
// Event: OnWebPagePrerender
 
$e = $modx->Event;
$account = isset($account)? $account: '';
$script = '
<script type="text/javascript" src="http://www.google-analytics.com/urchin.js"></script>
<script type="text/javascript">
    // Google Site tracking
    _uacct = "'.$account.'";
    urchinTracker();
</script>
';

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 );
}
break;

default :
return; // stop here - this is very important.
break;
}

#22: 24-Jun-2006, 01:15 PM

Foundation

rthrash
Posts: 11,348

WWW
Thanks lejoe
MODx is a content managmeent framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#23: 30-Jul-2006, 01:04 AM

Foundation

rthrash
Posts: 11,348

WWW
Now a part of the new Repository, FYI.
MODx is a content managmeent framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
Pages: 1 [2]  All   Go Up
0 Members and 1 Guest are viewing this topic.