Page 1 of 1

Cache and article hits issue

Posted: Tue Nov 20, 2012 9:16 pm
by vbarlakoski
Hello!

When i set cache option ON, on my joomla site, the article HITS stop counting at all.

How can i use cache properly but not affecting the counting function?

Thanks!

Re: Cache and article hits issue

Posted: Fri Nov 23, 2012 12:44 am
by vidak
Counting function is bad and doesn't give you proper information.
Use Google Analytic. It is about 98% right.

Re: Cache and article hits issue

Posted: Fri Nov 23, 2012 8:46 am
by vbarlakoski
That's kind of bad solution for this :)

Thanks anyway, i will wait for actual solution.

Re: Cache and article hits issue

Posted: Fri Nov 23, 2012 5:33 pm
by kenmcd
vbarlakoski wrote:When i set cache option ON, on my joomla site, the article HITS stop counting at all.
How can i use cache properly but not affecting the counting function?
EDITED

The full page cache affects anything which has regular updates.
Which is why the full page cache can often have limited usefulness.

.

Re: Cache and article hits issue

Posted: Fri Nov 23, 2012 5:55 pm
by vbarlakoski
So, Conservative cache caches just display or full page cache, because when cache expires, hits are not updated at all!

Re: Cache and article hits issue

Posted: Fri Nov 23, 2012 6:32 pm
by kenmcd
.
What I previously posted above was incorrect (so I edited it).

Hits are not counted in the background when the full page is cached.
Joomla counts hits when the page is built, and since it is not being built, no counting.

The best solution is to use external analytics as suggested above.

.

Re: Cache and article hits issue

Posted: Fri Nov 23, 2012 6:39 pm
by vbarlakoski
I have found third-party plugin CacheControl, and i forbid option=com_content&view=article to cache, so, i have my hits back.

Joomla developers should really look into this thing.

Thanks for help!

Re: Cache and article hits issue

Posted: Fri Nov 23, 2012 7:34 pm
by kenmcd
.
Then you have basically disabled caching for all content.
That makes no sense to me.
Just turn the cache plug-in Off instead.


.

Re: Cache and article hits issue

Posted: Fri Nov 23, 2012 7:39 pm
by vbarlakoski
Its off for Article View from com_content, not for blog view, not for featured view, not for modules outside that view, not for other components. How this does not make sense?

Re: Cache and article hits issue

Posted: Mon Nov 26, 2012 1:11 pm
by masoksian
same problem

system: Joomla 2.5.8

if cache enabled article hits stopping. :((

Re: Cache and article hits issue

Posted: Mon Nov 26, 2012 5:58 pm
by SimonHayter
To be honest, the hits counter within Joomla is pretty naff. Most opt to use external applications to monitor success of pages in a much detailed way than just 1 hit, 2 hits, and so on.

Re: Cache and article hits issue

Posted: Wed Dec 05, 2012 11:09 am
by vbarlakoski
Is there any way in template_name/html/com_content/article/default.php to make connection with the database and increase the hits count? In that way, that query wont be cached i think or i'm wrong?

It seems wrong that cache stops hits counting, because there is ordering by hits option.

Re: Cache and article hits issue

Posted: Fri Feb 21, 2014 4:00 pm
by bradm
I know this is an older post, but I was able to come up with a solution for my website, increasing hits even if a cached page is being served. I posted the basic concept of the solution here: http://joomlacode.org/gf/project/joomla ... m_id=29831

It does involve a change to the core, but it works, and that's what I needed. If anyone has any questions as to how to get this working, just let me know.

Re: Cache and article hits issue

Posted: Sat Mar 01, 2014 5:31 am
by itoctopus
Another way that doesn't involve modifying the core, is to create a system plugin that is run after the cache plugin runs, and that system plugin will update the page count. This'll work and it doesn't involve changing the core.

Re: Cache and article hits issue

Posted: Sat Mar 01, 2014 11:26 am
by vbarlakoski
There is a hack that works with Conservative and Progressive cache but not with System Cache.

In Site ROOT/index.php after $app->route(); insert this code:

Code: Select all

if (isset($_GET['view']) && strtolower($_GET['view']) == 'article') {
 $articleId = (int) $_GET['id']; 
  
 $db = JFactory::getDBO();
 $db->setQuery(
                        'UPDATE #__content' .
                        ' SET hits = hits + 1' .
                        ' WHERE id = '.(int) $articleId
                );

 $db->query(); 
}
This will update hits in database in real time, but in article view will update every time when cache session expires with actual database hits.

Re: Cache and article hits issue

Posted: Mon Mar 03, 2014 5:22 pm
by bradm
Hi @itoctopus and @vbarlakoski,

Great ideas! Were you able to prevent Joomla from updating the hits two times in the event someone was not seeing a cached version of the page? IE, the code / plugins you described would update the hits, and then the normal Joomla code would run and update the hit again.

Re: Cache and article hits issue

Posted: Mon Mar 03, 2014 5:25 pm
by vbarlakoski
Joomla code will run once to activate new cache. So it will update hit once. I think its better to have one time double hit every time cache expires, than have no hits at all while cache is active.

But, this is temporary fix, it should not be permanent one if you need to edit the core.

I hope that Joomla will adapt the system to work properly with or without cache. Hits must be excluded from caching.

Re: Cache and article hits issue

Posted: Mon Apr 28, 2014 7:53 am
by pankajsharma21+
HI
everyone
i tried the solution by @vbarlakoski
but the problem is still there ,
As i tested it for joomla 3.2.2 the article hit counter call is different in both cases(joomla3.2.2 and joomla2.5.x)

in joomla 3.2.2 the article hit counter is increased by

Code: Select all

	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;
	}


this code


I tried it to add in the root/index.php file but its not working for me , may be the issue is incorrect implementation of the above code .
is there anyone who will help me to solve this known joomla bug?
Regards

Re: Cache and article hits issue

Posted: Mon Apr 28, 2014 8:02 am
by vbarlakoski
I have done it this way:

I`m using jotCache for page caching.

Then i have created module that runs code for article hits increase.

Code: Select all

<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

if (isset($_GET['view']) && strtolower($_GET['view']) == 'article') {
 $articleId = (int) $_GET['id']; 
  
 $db = JFactory::getDBO();
 $db->setQuery(
                        'UPDATE #__content' .
                        ' SET hits = hits + 1' .
                        ' WHERE id = '.(int) $articleId
                );
 $db->query(); 
}

?>
Then I have excluded the module from JotCache caching.

This works perfectly in 2.5.

Re: Cache and article hits issue

Posted: Mon Apr 28, 2014 8:14 am
by pankajsharma21+
HI @vbarlakoski
is it custom html module ??
any idea for joomla3.2.2?

Re: Cache and article hits issue

Posted: Mon Apr 28, 2014 8:19 am
by vbarlakoski
You should try it.. Its custom module, that is changing the db values, so it should work in 3 too. Please share the result if you try it.

Re: Cache and article hits issue

Posted: Wed May 21, 2014 2:09 pm
by k2bmedia
Does it also work with K2 Items?

Re: Cache and article hits issue

Posted: Sat Jun 28, 2014 4:11 am
by pankajsharma21+
Hi the issue is solved .

Re: Cache and article hits issue

Posted: Fri Mar 11, 2016 12:33 pm
by kartov
vbarlakoski wrote: ' WHERE id = '.(int) $articleId
All of you be aware that this is SQJ Injection and this brings certain security risks. Did you ever heard about sanitizing inputs?

Re: Cache and article hits issue

Posted: Fri Dec 16, 2016 9:47 am
by changlee
vbarlakoski wrote:I have found third-party plugin CacheControl, and i forbid option=com_content&view=article to cache, so, i have my hits back...
Hello! Have you tried that option for Joomla 3.x also?

Re: Cache and article hits issue

Posted: Wed Mar 01, 2017 9:59 am
by alfa6
I made simple system plugin based on Your solution. I think plugin should fit better then module. Just install and enable it ("sittelicznik") in plugins.

Tested on Joomla 3.6.5 but it is so simple that it shuold work on all verssions.

Remember - if You disable cache then hits will by doubled every refresh. If You have cache enabled then hits will be doubled only from time to time so it's not precize solution.

Re: Cache and article hits issue

Posted: Tue Jun 20, 2017 9:20 pm
by Tov
not work on 2.7.2 :(

Re: Cache and article hits issue

Posted: Wed Jun 21, 2017 7:52 am
by pe7er
alfa6 wrote:I made simple system plugin based on Your solution. I think plugin should fit better then module. Just install and enable it ("sittelicznik") in plugins.

Tested on Joomla 3.6.5 but it is so simple that it shuold work on all verssions.
Actually, to have it working on Joomla 3 you should change the XML file

Code: Select all

<extension version="2.5" type="plugin" group="system">
should be

Code: Select all

<extension version="3.0" type="plugin" group="system">
See https://docs.joomla.org/Manifest_files