Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,187
    Rep Power
    220

    Add page view with php


    Hey

    Would it be accurate to increase the number of page loads in mysql wirth php when the visitor loads the page?

    Or could it be bots etc?

    Basically a simple db update query and update it each 30 second with ajax periodically and store ip etc etc

    Thanks
    Last edited by English Breakfast Tea; September 5th, 2017 at 07:57 AM.
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,325
    Rep Power
    9645
    Originally Posted by English Breakfast Tea
    Would it be accurate to increase the number of page loads in mysql wirth php when the visitor loads the page?
    Fairly accurate.

    Originally Posted by English Breakfast Tea
    Or could it be bots etc?
    Wouldn't that still count as a page load?

    Originally Posted by English Breakfast Tea
    Basically a simple db update query and update it each 30 second with ajax periodically and store ip etc etc
    Please no.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Location
    Bulgaria
    Posts
    15
    Rep Power
    0
    Do you want to know the page views count? Why would you periodically update it every 30 seconds? Just do it once when the page loads. Bots will also be counted, yes. If you want to ignore the bots, I guess you can run it after the page loads only on some event like moving the mouse, clicking, or touching the screen for mobile.
  6. #4
  7. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,325
    Rep Power
    9645
    You could always log the IP and user agent as a view (not increment some counter) then calculate view counts when needed. You can also adjust for legitimate bots (which typically have "bot" in their UA) or however you want.

    Or go third-party and try something like Google Analytics.
  8. #5
  9. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,187
    Rep Power
    220
    Originally Posted by Nikolay
    Do you want to know the page views count?
    Why would you periodically update it every 30 seconds?
    Just do it once when the page loads. Bots will also be counted, yes.
    If you want to ignore the bots, I guess you can run it after the page loads only on some event like moving the mouse, clicking, or touching the screen for mobile.
    Ok here is the idea:

    Code:
    $(document).ready(function () 
        {
    
            $( ".wrapper" ).mousemove(function(event)    
                {
                    $('#real_human').val(1);
                });
    Code:
    function update() 
    	{
    
    		  $.get("<?php echo base_url('update_views');?>", { real_human:  $("#real_human").val()}, function(data) {
    		    $("#div_reload").html(data);
    		    window.setTimeout(update, 60000);
    		  });
    	}
    
    $(document).ready(function() {
      // run the first time; all subsequent calls will take care of themselves
      setTimeout(update, 1000);
      
    });
    PHP Code:
    if($_POST['real_human']==1)
         {
             
    //Insert or update database based on ip
         

  10. #6
  11. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,187
    Rep Power
    220
    Originally Posted by requinix
    Please no.
    Why not? I wanna see how long they saty on the page.
  12. #7
  13. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,325
    Rep Power
    9645
    Originally Posted by English Breakfast Tea
    Why not? I wanna see how long they saty on the page.
    Because I get suspicious when I see a page calling back to a server without any interaction from me.

    I would use the unload event to send a request including page view time.
  14. #8
  15. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,187
    Rep Power
    220
    Originally Posted by requinix
    Because I get suspicious when I see a page calling back to a server without any interaction from me.

    I would use the unload event to send a request including page view time.
    How do you know when they exit page? I mean how do you know how long they stay on the page?
  16. #9
  17. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,325
    Rep Power
    9645
    Originally Posted by English Breakfast Tea
    How do you know when they exit page?
    https://developer.mozilla.org/en-US/.../Events/unload

    Originally Posted by English Breakfast Tea
    I mean how do you know how long they stay on the page?
    Use Date to track when the page first loaded and to calculate the time elapsed since.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Location
    Bulgaria
    Posts
    15
    Rep Power
    0
    I think that the mousemove event will not run on mobile. So you might want to use also add something like the touchmove or touchstart events. Look into them.
  20. #11
  21. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,780
    Rep Power
    4536
    Who cares how many people view a page? What do you do differently if 100 or 1,000,000 people view your page?

    Now, interactions with the page would be useful to track. How many database queries, insertions, edits, etc.

    How much activity?

    How many ad impressions? Those relate directly to income.

    Raw page views is worthless, imo.
    -- Cigars, whiskey and wild, wild women. --
  22. #12
  23. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,325
    Rep Power
    9645
    Originally Posted by Sepodati
    Who cares how many people view a page? What do you do differently if 100 or 1,000,000 people view your page?
    Knowing what people want to see means you can make more pages like that. This is a really, really important concept for content-based websites.
  24. #13
  25. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,780
    Rep Power
    4536
    Originally Posted by requinix
    Knowing what people want to see means you can make more pages like that. This is a really, really important concept for content-based websites.
    Sure, I agree, but I was counting that more under "actions" than just a page view. Unless you're serving a bunch of static content.
    -- Cigars, whiskey and wild, wild women. --
  26. #14
  27. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,187
    Rep Power
    220
    Originally Posted by Sepodati
    Who cares how many people view a page? What do you do differently if 100 or 1,000,000 people view your page?
    You're joking, right? This is key for split testing, conversion tracking....
  28. #15
  29. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,780
    Rep Power
    4536
    Originally Posted by English Breakfast Tea
    You're joking, right? This is key for split testing, conversion tracking....
    Not joking, but I probably didn't state it right. I was trying to impress that's it's more important to understand what people are doing on your site rather than tracking raw page views.
    -- Cigars, whiskey and wild, wild women. --
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo