We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16907
    • 1 Posts
    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:

    // 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; 
    }
    
    • Thanks lejoe
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • Now a part of the new Repository, FYI.
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me