0

I need to count how many times a div is viewed. Most hit counters count how many times a page is loaded but I want to count how many times a div is viewed. There are different pages that this div is located on and I need to know how many times it is viewed in total...regardless of what page it is viewed on. Please help!!!! I have spent 20hrs on this and I'm a newbie in desperation. Thanks.

user2152326
  • 279
  • 1
  • 3
  • 7
  • [What have you tried?](http://whathaveyoutried.com) Place a view counter in the div? – chriz Mar 26 '13 at 13:41
  • I've tried to place a hit counter in the div but that only displays when the page is loaded. It's also from an external source which I don't want because I have to provide a link to their site and rely on their connection. I have also tried to add some Asp.net code from a site but it doesn't work. My site isn't live yet and that might be the cause? I need multiple individual counters in multiple divs. I've tried and am continuing to try learning other languages to accomplish this but I just don't know how to go about making a div view counter. – user2152326 Mar 26 '13 at 15:05
  • Make your own? there are plenty of php view counter tutorials out there. Then simple call it in the div – chriz Mar 26 '13 at 15:08
  • ok, thanks. I have 100 divs on a page. Just because a user views a page doesn't mean he scrolls down and views the 99th div. Can a php view counter do this? In other words, only count when a div is viewed and not when a page is viewed. – user2152326 Mar 26 '13 at 15:12
  • updated my answer, you can use `jQuery` to detect that. I cant give you the exact code for this im afriad, but I can point you in the right direction. – chriz Mar 26 '13 at 15:17

1 Answers1

0

There are many php hit counter tutorials out there.

Heres one I found doing a google search:

https://code.google.com/p/simphp/

All you would have to do is call:

<? include("home/public_html/hits/simphp.php"); ?>

Then place this in the div you want counted:

<div id="count"><? echo $info; ?></div>

To detect if a div is visible in the browser window, use jQuery:

Check if div is viewable in window?

Community
  • 1
  • 1
chriz
  • 1,510
  • 18
  • 27