• Resolved stokim2012

    (@stokim2012)


    Hi Héctor ??

    I have some suggestions regarding this plugin:)

    1. Can you limit the view count to one per ip on the same post to prevent fraudulent clicks?

    2. Is it possible to count views only for logged-in users to prevent fraudulent clicks?

    Thank you ??

    Best regards,
    Jen

    • This topic was modified 6 years, 7 months ago by stokim2012.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi Jen!

    Thanks for the suggestions!

    1. Can you limit the view count to one per ip on the same post to prevent fraudulent clicks?

    You might want to check this ?? (make sure to read the whole thread though, I made some observations you should be aware of).

    2. Is it possible to count views only for logged-in users to prevent fraudulent clicks?

    Yep ?? Go to Settings > WordPress Popular Posts > Tools, and under Data you’ll find the option “Log views from”. Set it to “Logged-in users only”, hit the Apply button to save changes and you’re done!

    Thread Starter stokim2012

    (@stokim2012)

    Thanks for your help @hcabrera
    I read all of replies on that post.

    I got to know know it can count views for logged-in user, then how about delete duplicated view counts per username on the same post /24 hours?

    Does it equally burden a server to erase duplicated IP?

    I think it would be better if only the logged-in users’ views are counted, and then delete duplicated usernames’ views for efficiency!

    • This reply was modified 6 years, 7 months ago by stokim2012.
    Plugin Author Hector Cabrera

    (@hcabrera)

    Hey Jen,

    Does it equally burden a server to erase duplicated IP?

    Yep, it’s basically the same thing. In your specific case, however, you’ll be doing this with logged-in users only so I don’t think your site’s performance will suffer too much.

    Edit

    Ah, almost forgot. You’ll want to update the function so it doesn’t run for non-logged-in visitors:

    /**
     * Have WordPress Popular Posts store one view 
     * per entry per IP per day to keep visitors from 
     * inflating the views count.
     */
    function wpp_unique_view( $post_ID, $views ){
    
        if ( !is_user_logged_in() ) 
            return;
    
        $ip_address = $_SERVER['REMOTE_ADDR'];
        $transient_name = 'wpp_' . $post_ID . '_' . $_SERVER['REMOTE_ADDR'];
    
        // Visitor has already seen this page
        if ( get_transient( $transient_name ) ) {
            exit();
        }
    
        // Visitor has not seen this page yet
        $timezone = new DateTimeZone( 'GMT' . get_option( 'gmt_offset' ) );
        $now = new DateTime( 'now', $timezone );
        $midnight = new DateTime( 'tomorrow midnight -1 second', $timezone );
        $interval = $midnight->diff( $now );
    
        $expire = $interval->h * 3600 + $interval->i * 60 + $interval->s;
    
        // Keep this record until midnight
        set_transient( $transient_name, 1, $expire );
    
    }
    add_action( 'wpp_pre_update_views', 'wpp_unique_view', 10, 2 );
    • This reply was modified 6 years, 7 months ago by Hector Cabrera. Reason: Updated code
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I have some suggestions regarding this plugin:)’ is closed to new replies.