We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4018
    • 1,131 Posts
    I thought I’d post a shortened version of how to use Mint with MODx. For those who have not read my blog post about using Mint with MODx, you can read up on it here:
    http://modxcms.com/index.php?id=337

    Integrating Mint with MODx is incredibly easy. First things first, you’ll need to install Mint into it’s own directory; just follow the directions that comes with Mint. I recommend creating a new directory in the root of your MODx site and installing it there since it’ll make it easier to access Mint without the need of typing in a bunch of directory names. Also, I recommend that you copy the .htaccess file from the manager directory on over into your Mint directory. This will ensure that the Apache rewrite engine is turned off and doesn’t interfere with Mint.

    Once Mint is installed and you know that it’s working, now you need to log into the MODx manager and add a simple snippet. I called mine ’MintStats’ but you can call it whatever you wish. For the snippet code, insert the following lines:

    if($this->isFrontEnd() && !isset($_SESSION['mgrValidated'])){
        $script = '<script src="/mint/?js" type="text/javascript"></script>';
    }
    return $script;
    


    The only thing you really need to change with the snippet code is the script src line. If your Mint directory isn’t ’mint’ then you’ll need to change it. So if your Mint directory is ’stats’ then the snippet code would be changed to this:

    if($this->isFrontEnd() && !isset($_SESSION['mgrValidated'])){
        $script = '<script src="/stats/?js" type="text/javascript"></script>';
    }
    return $script;
    


    Although the path will work just fine as a root relative URL, there may be times when a full URL might be needed; for instance, when you are tracking a subdomain with a full domain. In that case, you’ll need to add the full URL to the beginning of the path:

    if($this->isFrontEnd() && !isset($_SESSION['mgrValidated'])){
        $script = '<script src="http://www.mydomain.com/stats/?js" type="text/javascript"></script>';
    }
    return $script;
    


    The script src line can also be changed so that it uses a full URL instead of a root relative URL simply by adding ’[(site_url)]’ to the beginning of the path. This can be handy if your server has problems utilizing root relative script sources:

    if($this->isFrontEnd() && !isset($_SESSION['mgrValidated'])){
        $script = '<script src="[(site_url)]stats/?js" type="text/javascript"></script>';
    }
    return $script;
    


    After you save the snippet, it’s just a simple matter of inserting the snippet into each of the templates you wish pages to be tracked from. Insert the snippet code just before the ending </head> tag for each template like so:

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>[(site_name)] | [*pagetitle*]</title>
    <script type="text/javascript"></script>
    <style type="text/css">
    	@import url('[(site_url)]assets/templates/default/site.css');
    </style>
    [!MintStats!]
    </head>
    <body>
    


    The snippet needs to be uncached or else the snippet will be unable to properly read the necessary session variables. All the snippet does is check to see if it is being runned from the frontend or not and whether or not if a user is logged into the manager. This keeps the script from being displayed when a user is logged into the manager and from appearing when a page is being previewed from within the manager. Thus, Mint won’t log any activity from within the manager or when QuickEdit is being used. You can check this simply by logging into the manager and viewing the source of a page. If the script isn’t being inserted then Mint isn’t tracking the page. If you logout of the manager, restart your browser, and visit your site you should see that the script is being inserted. After you do this, check to see if Mint recorded your visit. So long as you didn’t check the option "Ignore my visits (uses cookies)" then Mint should record your visit.

    And that’s pretty much it! Pretty easy! And as I said on my blog post...Mint may not be the end-all of stat applications, but it’s still pretty damn cool! smiley

    Jeff

      Jeff Whitfield

      "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
      • 32241
      • 1,495 Posts
      That’s a cool walkthrough, So should i put this on snippet repository wink
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
      • Add away Wendy!

        Jeff, any reason to NOT append the [(site_url)] variable to each call?
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 4018
          • 1,131 Posts
          Quote from: rthrash at Feb 07, 2006, 10:00 PM

          Jeff, any reason to NOT append the [(site_url)] variable to each call?

          No reason really. The root relative way is the method used by default for Mint. Doesn’t hurt either way. Though I will say that if you’re tracking a subdomain then the subdomain will need to use the full URL of the site that’s hosting the Mint installation. Thus you can’t use the [(site_url)] variable in such case.
            Jeff Whitfield

            "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
          • Any reason not to implement as a plugin like the Google Analytics one?
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 4018
              • 1,131 Posts
              Quote from: rthrash at Feb 07, 2006, 10:22 PM

              Any reason not to implement as a plugin like the Google Analytics one?

              No...no reason at all! In fact, I like that idea much better! Better said than done! I’ll get it whipped up and will redo the tutorial here with it. Oh...btw...you suck! LOL! j/k! I just wish I had thought of it sooner! smiley
                Jeff Whitfield

                "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
              • just dupe it off the Google Analytics one... they both do the same thing (insert a tiny bit o’ JS...). smiley Definitely a reason to have a snippet and also to have a plugin, though.
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 32241
                  • 1,495 Posts
                  Kewl, let me know when this is done. I wisll surely put this up on repository. wink
                    Wendy Novianto
                    [font=Verdana]PT DJAMOER Technology Media
                    [font=Verdana]Xituz Media
                  • Jeff, here’s my go at the plugin, can you verify this works since I’ve not been Minted:
                    <?php
                    // Mint Site Stats Plugin by Ryan Thrash
                    // 8-Feb-2006 
                    // version 1.0
                    //
                    // Adds your Mint Stats tracking JS to every page in your site with hit logging enabled.
                    //
                    // Parameter: &install=Install Location;string;[(site_url)]stats/?js 
                    // Event: OnWebPagePrerender 
                    
                    $e = $modx->Event; 
                    $install = isset($install)? $account: '[(site_url)]stats/?js';
                    $script = '
                    <script src=".$install." type="text/javascript"></script>
                    '; 
                    
                    switch ($e->name) { 
                    	case "OnWebPagePrerender": 
                    		$haveamint = ($modx->documentObject['donthit']==0 && $modx->documentObject['contentType']=='text/html' && !isset($_SESSION['mgrValidated']));
                                  if ($haveamint) { 
                    			$modx->documentContent = preg_replace("/(<\/head>)/i", $script."\n\\1", $modx->documentContent); 
                    		}
                    		break;
                    
                    	default : 
                    		return; // stop here - this is very important. 
                    		break; 
                    }
                    ?>
                    
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 4018
                      • 1,131 Posts
                      Hmmm...ran into a snag! It seems that plugins don’t parse either [(base_url)] or [(site_url)]. Is this correct?
                        Jeff Whitfield

                        "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."