WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: hitcounter] Double Count (17 posts)

  1. DigitalAlias
    Member
    Posted 3 years ago #

    I just installed hitcounter today. Very neat feature, I like it's simiplicity. I noticed though, that the count increments are done in 2's instead of 1. Any page I visit will show that it's been seen twice.

    http://www.fergytech.com

    http://wordpress.org/extend/plugins/hitcounter/

  2. Tom(dB)
    Member
    Posted 3 years ago #

    Hi DigitalAlias,

    the plugin works by adding 1 to the view count in the database when the_content() is called on a single page ( is_single() ). All I can think of right now is that the_content() is called more than once, somehow, on your page.

    Could you post your single.php on http://pastebin.com/ or some service like that so I could have a look.

    I'll just do a bit more research into adding filters on the_content as well.

  3. Tom(dB)
    Member
    Posted 3 years ago #

    I figured out the problem. If the_excerpt() is displayed on the page as well as the the_content() the code runs twice since they are both returning $content.

    I've just trying to figure out how to make it act only on full content...

  4. Tom(dB)
    Member
    Posted 3 years ago #

    I've come up with a fix for this by offering an option on the settings page.

    Version 1.2 will be with you shortly. Just a bit more testing to do.

  5. DigitalAlias
    Member
    Posted 3 years ago #

    Very cool. Thanks for looking into this. In the "settings" page is there an option to reset the count - either by page or the entire site?

  6. Tom(dB)
    Member
    Posted 3 years ago #

    There isn't. I'll add it to the "things to do" list.

    Perhaps have the reset post count on the post edit page itself, and a reset entire site in the setting page (with an "are you sure?" check)?

    I'll have a think about it.

  7. TadeuszD
    Member
    Posted 3 years ago #

    Hi, Tom,
    I just downloaded and installed your plugin. The plugin is very nice, simple and consumes a little resources. It is exactly, what I need! :)

    But I encountered the simple problem. The plugin don't work with newest version of mySQL. In the 'CREATE TABLE' command you declare fields as 'NOT NULL', but function logCount don't fill all corresponding fields. I correct this error by adding 'DEFAUL 0' to fields declaration.
    Can you correct this problem in official version of your plugin?

  8. TadeuszD
    Member
    Posted 3 years ago #

    Hi, once again...
    I've detected, that your plugin is gathering data for all posts, including deleted posts and revisions...

    I now, this is only theoretical problem. But I think, the option "Reset all counters", by deleting all rows from hitcounter table, will be very usefull in this situation. :)

  9. Tom(dB)
    Member
    Posted 3 years ago #

    Hi TadeuszD, thanks for your feedback. You're right about the DEFAULT 0 value. That's easily sorted.

    Deleting view count: I've been thinking about this. If I have the reset button within the post edit page it needs to not refresh the page when clicked (and lose any changes you've made that havent saved) so I need to get my head around using AJAX in plugins. It doesn't look too complex but I need to have a mess around with it.

    Regarding the 'theoretical problem'. Are you saying that if you look at a deleted post, or a post revision, it counts as a view? I could do a check on post_status but it would require another database lookup.

    Hitcounter was never meant to be the be all and end all in viewing statistics. It was just to act as a guide as to the popularity of a post.
    Do you think it's worth doing .1 release to add the DEFAULT status (you're the first to mention it) or wait until I figure out the AJAX thing?

  10. TadeuszD
    Member
    Posted 3 years ago #

    Hi,
    About 'theoretical problem' - I wil check it again... I've tested many modification and it may be my fault. :( Please, don't disturb yourself about this problem at this time.

    About 'reset counters' - The great advantage of your plugin is the siplicity. In my opinion using AJAX for reset counters is like "using the cannon to kill the mosquito" (this is the polish idiom).

    I'm thinking now... Reset counters option is only needed if we are generating many 'false-views' itself, while preparing and correcting posts. Instead of 'reset' option, you can add option which means "ignore users with security level greater than...". This option will allow us to ignore our (admins or redactors) activity. What do you think about it?

  11. DigitalAlias
    Member
    Posted 3 years ago #

    Hi tomdebruin,

    I'm having a problem. The counter doesn't seem to work anymore. Well; it doesn't work when I check (enable) "Act on the_excerpt(); only" option. When I uncheck it, the counter works, but does doubles. When I check the option nothing is getting captured.

    http://www.fergytech.com

  12. Tom(dB)
    Member
    Posted 3 years ago #

    Hi DigitalAlias, could you post your single.php code on http://pastebin.com/ or some service like that so I could have a look?

  13. blueboxed
    Member
    Posted 3 years ago #

    I am too receiving double counts. If you could help me out I would greatly appreciate it! I have enabled the option for ignoring admin users, and when checking on a different computer, not logged into the site, I still receive double counts.

    http://pastebin.com/Ww1F8r97

  14. Tom(dB)
    Member
    Posted 3 years ago #

    Hi blueboxed,

    I just used your code on a site and I'm just getting one count increment. Are you using the latest version of the plugin?

  15. blueboxed
    Member
    Posted 3 years ago #

    Hmm thats odd. I just installed the plugin yesterday, so it's up to date. The site is leakplay[] com. Im wasn't sure if it had something to do with the excerpt being called or not, so I've tested the placement of the count code & it counts by two regardless of where I put the code (widget, footer, etc).

    Thanks for your quick response!

  16. Tom(dB)
    Member
    Posted 3 years ago #

    @blueboxed, sorry for the delay in getting back to you, I've been away.

    Just had a look at your site, and had another look at the single.php code and it might possibly have something to do with line 42 - if (have_posts()) : while (have_posts()) : the_post(); ?>. Maybe the the_post is getting called again even if a valid post has been found - therefore counting for a second time.

    If you look at line 147 in hitcounter.php you'll see add_filter('the_post', 'hc_detectAgent');. Experiment by changing the_post to the_excerpt or the_content (e.g. add_filter('the_content', 'hc_detectAgent');) and see if one of those options changes it for you.

    Alternatively take out the else statement in your single.php and create a 404.php file to handle errors.

    Let me know how it goes.

  17. rafdevis
    Member
    Posted 3 years ago #

    Hi Tom,

    I managed to get single counts on my homepage by changing add_filter('the_post', 'detectAgent'); to add_filter('the_content', 'detectAgent');

    But this doesn't do the trick for single pages where I still get double counts.

    Any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags