The Joomla!® User Experience Portal

Welcome, Guest
Username Password: Remember me

Not Count Own Hits with Articles
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Not Count Own Hits with Articles

Not Count Own Hits with Articles 11 months, 1 week ago #797

  • Josh
  • OFFLINE
  • Posts: 23
  • Karma: 0
When ever I made an article I am usually logged into the frontend and check it from time to time. It would be great if my own hits were not included in the article hit counter.

Re: Not Count Own Hits with Articles 7 months, 1 week ago #1256

It's probably one of the very useful features that could be implemented in the new base com_content, especially if, for instance, you have a Facebook comment plugin for articles, where you need to moderate the posts, by visiting the article in the front-end.

A simple multiple selection option, added to Articles backend configuration, could look like:

Disable hit counter? Author, Admin, All

Since the class ContentModelArticle method hit() that performs the task of incrementing the hit, is already checking for !$this->params->get('intro_only') (in components/com_content/views/view.html.php line 142) , disabling hit increment if in intro view, it could as well check for a possible additional parameter 'counter_disable'.

Not sure if there's a plugin for this but it's really an option that makes sense to be part of the main package, in my opinion.
Last Edit: 7 months, 1 week ago by marioppro.
The following user(s) said Thank You: Josh

Re: Not Count Own Hits with Articles 6 months, 4 weeks ago #1284

  • Josh
  • OFFLINE
  • Posts: 23
  • Karma: 0
I'd say I'm one of the most familiar people with the JED and what extensions it has. I probably have gone though at least 80% of it over a long period of time. I have yet to see such a extension.

I like the idea you mentioned. This becomes even more important for cases were I have to go back and forth making edits to an article for a buddy of mine today which I racked up hits very fast.
The following user(s) said Thank You: marioppro

Re: Not Count Own Hits with Articles 6 months, 4 weeks ago #1287

I have coded and tested this feature with success. This enables the admin configuration for articles to exclude (do not count) front-end views (hits) on articles by users belonging to the specified groups.
Hope it helps

Simple changes only need to be implemented in the following scripts:

administrator/components/com_content/config.xml I've done the following:

 
<field name="count_hits"
type="UserGroup"
multiple="true"
size="20"
label="COM_CONTENT_DISABLE_HIT_COUNT_LABEL"
description="COM_CONTENT_DISABLE_HIT_COUNT_DESC"/>
 


and in

components/com_content/views/article/view.html.php I've done the following:

Changes near line 138

 
// Increment the hit counter of the article.
$groups = $user->getAuthorisedGroups();
 
if(!$this->params->get('intro_only') && $offset == 0 && $this->countHits($groups) == true) {
 


Added new method near line 155

 
/**
* Checks if user is within the groups that should'nt increase the articles' hits
*
* @param $groups Array containing the groups to exclude
* @return bool Returns false (don't count) if user in selected groups
*/

private function countHits($groups)
{
$countHits = true;
$count = $this->params->get('count_hits', false);
if($groups && $count) {
for ($n = 0, $i = count($groups); $n < $i; $n++) {
if(in_array($groups[$n], $count)) {
// User is in the group
$countHits = false;
}
}
}
return $countHits;
}


in administrator/language/en-GB/en-GB.com_content.ini needs just a couple lines added:

 
COM_CONTENT_DISABLE_HIT_COUNT_LABEL="Disbale hit count"
COM_CONTENT_DISABLE_HIT_COUNT_DESC="Select the user group or groups that will not increment the article hits in the front-end."
 
Last Edit: 6 months, 4 weeks ago by marioppro. Reason: language changes
The following user(s) said Thank You: Josh

Re: Not Count Own Hits with Articles 6 months, 4 weeks ago #1289

  • Josh
  • OFFLINE
  • Posts: 23
  • Karma: 0
This looks really cool. Thanks for taking the time to make this. I have yet to test it because I have a few questions:
Who is the specific groups? I assume admins and article owners?

But what about editors? People with editing privileges I want to be able to count their hits. You might ask why. Because my site is mostly a wiki set up which most of the editors (most of the users) will be looking at the article and not actually editing the article. This idea of not counting hits however is useful for the section where private content is posted.

So does the above code make it so editor (usergroup) hits do count? I would love to have it that way.
Last Edit: 6 months, 4 weeks ago by Josh.

Re: Not Count Own Hits with Articles 6 months, 4 weeks ago #1291

As you may see on the attached screenshot from my working administrator area, you can select any/none/all/some from the settings. Whoever belongs to the groups selected, the hits won't count.

I presume that it could go even deeper to article level, i.e. setting this system for each article in the individual article options, but after thinking for a while, I'm really not so keen about that approach.

(btw, in the screenshot I've selected, for demo purposes, all possible groups, so in this case the hits are globally disabled.)
Attachments:
Last Edit: 6 months, 4 weeks ago by marioppro. Reason: added comment
The following user(s) said Thank You: Josh

Re: Not Count Own Hits with Articles 6 months, 4 weeks ago #1292

  • Josh
  • OFFLINE
  • Posts: 23
  • Karma: 0
That looks great! Glad we got the editor question figured out.

So can this method be used to disable the hit count for article owners? For example if I (non admin) view my own article, could those views not count? I really appreciate you looking into this. Kunena (this forum) is a great example of this. When I view this thread, no views are added.

Re: Not Count Own Hits with Articles 6 months, 4 weeks ago #1293

In this stage (beta) It will disable the hit count for specific groups and not for individual article owners, but that seems fairly simple to add to this.

In your example, your hits wouldn't be counted on articles as long as you're assigned to the Authors group and the Authors group is selected in the articles options (the screenshot field).
  • Page:
  • 1
  • 2
Time to create page: 0.59 seconds