We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    Looking at this counter... I need one that works for individual pages rather than a blanket count.
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 3707
      • 241 Posts
      I don’t see why Page Hit Counter won’t work for you. It does just that, counts the number of times a page has been viewed. It just doesn’t display the count on the web page.

      Try installing the page counter module and plugin and then use it with this snippet:
      <?php
      $prefix = $modx->dbConfig['table_prefix'];
      $page = '';
      $page_id = isset($id) ? $id : $modx->documentObject['id'];
      
              $sql = "SELECT page_count FROM " .$prefix. "page_hit_counter WHERE page_id ='" .$page_id."'";
              $rs = $modx->db->query($sql);
      	$row = $modx->db->getRow($rs);
              $page .= "Page views: " . $row['page_count'];
      
      return $page;
      ?>

      Create a new snippet called pageCount or something and add that code, then call [!pageCount!] wherever you want the count to appear in your document.

      It’s a very basic snippet but it works on the test I did.
        • 25551 ☆ A M B ☆
        • 1,231 Posts
        Quote from: bob1000 at Jul 07, 2008, 09:37 AM

        I don’t see why Page Hit Counter won’t work for you. It does just that, counts the number of times a page has been viewed. It just doesn’t display the count on the web page.

        Try installing the page counter module and plugin and then use it with this snippet:
        <?php
        $prefix = $modx->dbConfig['table_prefix'];
        $page = '';
        $page_id = isset($id) ? $id : $modx->documentObject['id'];
        
                $sql = "SELECT page_count FROM " .$prefix. "page_hit_counter WHERE page_id ='" .$page_id."'";
                $rs = $modx->db->query($sql);
        	$row = $modx->db->getRow($rs);
                $page .= "Page views: " . $row['page_count'];
        
        return $page;
        ?>

        Create a new snippet called pageCount or something and add that code, then call [!pageCount!] wherever you want the count to appear in your document.

        It’s a very basic snippet but it works on the test I did.

        Hey thanks for the idea here... I have the Page Hit Counter module installed and it’s displaying counts in the manager but not on a webpage. It’s showing the Page Views line from the snippet but not the info from the module...
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart
          • 3707
          • 241 Posts
          So it’s displaying "Page views:" but no numbers?

          Did you make sure the "Log visits (stats)" checkbox was checked for the pages you look at and that you’re not logged into the manager?

          As I said, this is a basic snippet and it doesn’t show any results if the page has no views. Try this instead, I’ve just added a record count to check if there is an entry in the table:
          <?php
          $prefix = $modx->dbConfig['table_prefix'];
          $page = '';
          $page_id = isset($id) ? $id : $modx->documentObject['id'];
          
                  $sql = "SELECT page_count FROM " .$prefix. "page_hit_counter WHERE page_id ='" .$page_id."'";
                  $rs = $modx->db->query($sql);
          	$row = $modx->db->getRow($rs);
          	$count = $modx->recordCount($rs);
          	if ($count < 1) {
                          $page .= "Page views: 0";
          	} else {
                          $page .= "Page views: " . $row['page_count'];
          	}
          
          return $page;
          ?>
            • 25551 ☆ A M B ☆
            • 1,231 Posts
            Thanks bob, that worked! How accurate is the page counter anyway?
              Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
              AugmentBLU - MODX Partner

              BLUcart - MODX Revolution E-Commerce & Shopping Cart
              • 3707
              • 241 Posts
              You’re welcome, anything to help. I’m sure that script could be improved a lot, I’m not a programmer so it could probably be written much better.

              I don’t know how accurate page counter is, I haven’t really looked at the code. In my experience of the different stats and analytics software I’ve used in the past, they all give slightly different results. I find them more useful as a relative measure rather than for definitive results.
                • 25551 ☆ A M B ☆
                • 1,231 Posts
                Yeah it’s good of you, thanks. It’s not imperative that the stats are 100% correct. Anyway I just sat and held on to my refresh button on 1 of my test pages and it counted every refresh so seems to be pretty decent.

                Ross
                  Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                  AugmentBLU - MODX Partner

                  BLUcart - MODX Revolution E-Commerce & Shopping Cart