7

I have just installed Joomla 3.3. I'd like to have the chance to avoid incrementing the visitor counter while I visits my own pages. Is it possible at least when I'm logged in?

  • I'm sure there will be a way to do this. Are you referring to Joomla's built in stats counter or another extension? What have you tried so far? – Lodder Sep 22 '14 at 15:10
  • Honestly, I don't ever look at those page counts. I install google analytics and then set my office IP to not count in the stats. The issue is, if you're NOT logged in on the front, you can ONLY do it via IP anyway. I guess I always looked at those page counters as a gimmick for small sites and not something realistic. – Brian Peat Sep 24 '14 at 15:12
4

You can create a plugin like this:

class plgContentReduceHits extends JPlugin
{
    public function onContentAfterDisplay($context, &$article, &$params, $limitstart)
    {
        if ($context == 'com_content.article' && JFactory::getUser()->id == $article->created_by && $params->get('intro_only'))
        {
            $db = JFactory::getDbo();
            $db->setQuery('UPDATE #__content SET hits = hits - 1 WHERE id = ' . $article->id);
            $db->execute();
        }
        return '';
    }
}

The above plugin works. It is obvious that you must be logged into your site and the plugin should be enabled.

| improve this answer | |
  • 1
    Oohh!! Excellent! Only bad piece is that you have 2 queries to effectively do nothing, but it is just for your page views, so probably not a big deal. – David Fritsch Sep 23 '14 at 15:17
  • @DavidFritsch, yeah, in fact maximum one excessive query. IMHO it is worth and not a big issue. – Farahmand Sep 24 '14 at 8:09
2

Assuming you are talking about Joomla's built in hit counter, the answer as far as I have seen is "no". The code that runs this is super simple and offers no real means to adapt this in the CMS. (The code won't even increment the hit counter if you enable caching...)

What currently happens in the article's view.html.php file is this:

// Increment the hit counter of the article.
if (!$this->params->get('intro_only') && $offset == 0)
{
    $model = $this->getModel();
    $model->hit();
}

Basic check to make sure that this is the start of loading the full article. If so, trigger the model to record a hit.

The model does this:

public function hit($pk = 0)
{
    $input = JFactory::getApplication()->input;
    $hitcount = $input->getInt('hitcount', 1);

    if ($hitcount)
    {
        $pk = (!empty($pk)) ? $pk : (int) $this->getState('article.id');
        $db = $this->getDbo();

        $db->setQuery(

            'UPDATE #__content' .
                ' SET hits = hits + 1' .
                ' WHERE id = ' . (int) $pk
        );

        try
        {
            $db->execute();
        }
        catch (RuntimeException $e)
        {
            $this->setError($e->getMessage());
            return false;
        }
    }
    return true;
}

Basically, increment the hit column on the article.


If you want to adjust the behavior of this currently, your only choice is to edit the core code (and have the inherent issues with that when you try to update).

There isn't any way to "intercept" this action and trigger a plugin to perform an alternate action. The best bet is to ignore the hit column on articles and use a better measure of how many views your articles are getting (with Google Analytics probably being the most popular choice).

| improve this answer | |
  • I thank you for the reply. I've already found it in this link but I hoped to see this function implemented in the vanilla version of joomla after more than one year. I don't think it should be so painful to accept the change into the core, isn't it? – usernumberone Sep 23 '14 at 8:26
  • Yeah, code in the forum will never make it into the core. You would actually have to submit the code through github. The logic of this seems good, so you should feel free to make that pull request. – David Fritsch Sep 23 '14 at 15:19
1

I just stumbled upon a plugin at JED called JProNoHitCount (http://extensions.joomla.org/extensions/authoring-a-content/admin-interface/22961) that allows you to select one or more groups to be excluded from the article hit counter.

(Note that it's a commercial plugin).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.