Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 10th, 2008, 04:44 PM
anamasan anamasan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 2 anamasan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 50 sec
Reputation Power: 0
Question Javascript hitcounter over counting hits

I inherited a website with a javascript hit counter that displays realtime hit counts that are 10 times the hits that google logs for the website. Can someone review the script to help me repair the overcount?

Reply if you want to see the javascript Code

Last edited by anamasan : June 10th, 2008 at 04:45 PM. Reason: message was too long

Reply With Quote
  #2  
Old June 10th, 2008, 05:54 PM
ChiefWigs1982's Avatar
ChiefWigs1982 ChiefWigs1982 is offline
Cunning Linguist
ASP Free Loyal (3000 - 3499 posts)
 
Join Date: Mar 2005
Location: I used to live at home, now I stay at the house
Posts: 3,396 ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 50746 Folding Title: Beginner FolderFolding Points: 50746 Folding Title: Beginner FolderFolding Points: 50746 Folding Title: Beginner Folder
Time spent in forums: 1 Month 1 Week 3 Days 11 h 28 m 23 sec
Reputation Power: 307
Facebook
Ok, I'll bite. Let's see it.

You realise that you can't actually use JavaScript on it's own for
counting hits - it is only a client side scripting language - it has
no way of storing the data gathered.
__________________
Support requests via PM will be ignored!
Route of Queue | The General FAQ Thread | HOW TO POST A QUESTION

Sign up with Matched.co.uk and earn up to £15 per website every month!


Reply With Quote
  #3  
Old June 10th, 2008, 06:46 PM
anamasan anamasan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 2 anamasan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 50 sec
Reputation Power: 0
yes. its a dynamic website with a database.

Quote:
Originally Posted by ChiefWigs1982
Ok, I'll bite. Let's see it.

You realise that you can't actually use JavaScript on it's own for
counting hits - it is only a client side scripting language - it has
no way of storing the data gathered.


Yes. its a dynamic website with a database. Thanks for your help!
Here is the code:

Code:
var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject() 
 {
 var xmlHttp;
 try
  { xmlHttp = new XMLHttpRequest(); }
 catch(e)
  {
  var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                  "MSXML2.XMLHTTP.5.0",
                                  "MSXML2.XMLHTTP.4.0",
                                  "MSXML2.XMLHTTP.3.0",
                                  "MSXML2.XMLHTTP",
                                  "Microsoft.XMLHTTP");
  for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
   {
   try { xmlHttp = new ActiveXObject(XmlHttpVersions[i]); }
   catch (e) {  }
   }
  }
  //xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (!xmlHttp) { return; }
  else { return xmlHttp; }
 }

function showCount()
 {
 if (xmlHttp)
  {
  try
   {
   xmlHttp.open("GET", "../count.txt?sid=" + Math.random(), true);
   xmlHttp.onreadystatechange = handleRequestStateChange;
   xmlHttp.send(null);
   }
   catch (e) { return; }
  }
 }

function showCountSec()
 {
 if (xmlHttp)
  {
  try
   {
   xmlHttp.open("GET", "../count.txt?sid=" + Math.random(), true);
   xmlHttp.onreadystatechange = handleRequestStateChangeSec;
   xmlHttp.send(null);
   }
   catch (e) { return; }
  }
 }

function handleRequestStateChange() 
 {
 myDiv = document.getElementById('counter');
 var response = '';
 if (xmlHttp.readyState == 4) 
  {
  if (xmlHttp.status == 200)
   {
   try
    {
    response = xmlHttp.responseText;
    myDiv.innerHTML = formatCommas(response);
    }
   catch(e) { return; }
   } 
  else { return false; }
  }
 }

function handleRequestStateChangeSec() 
 {
 myDiv = document.getElementById('sDoc');
 var response = '';
 if (xmlHttp.readyState == 4) 
  {
  if (xmlHttp.status == 200)
   {
   try
    {
    response = xmlHttp.responseText;
    myDiv.innerHTML = formatCommas(response);
    }
   catch(e) { return; }
   } 
  else { return false; }
  }
 }

function uncache(url)
 {
 var d = new Date();
 var time = d.getTime();
 return url + '&time='+time;
 }

function formatCommas(numString)
 {
 var re = /(-?\d+)(\d{3})/;
 while (re.test(numString)) { numString = numString.replace(re, "$1,$2"); }
 return numString;
 }

Last edited by mehere : June 10th, 2008 at 08:46 PM. Reason: added code tags ... please use [code][/code] tags in the future.

Reply With Quote
  #4  
Old June 11th, 2008, 03:27 AM
ChiefWigs1982's Avatar
ChiefWigs1982 ChiefWigs1982 is offline
Cunning Linguist
ASP Free Loyal (3000 - 3499 posts)
 
Join Date: Mar 2005
Location: I used to live at home, now I stay at the house
Posts: 3,396 ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)ChiefWigs1982 User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 50746 Folding Title: Beginner FolderFolding Points: 50746 Folding Title: Beginner FolderFolding Points: 50746 Folding Title: Beginner Folder
Time spent in forums: 1 Month 1 Week 3 Days 11 h 28 m 23 sec
Reputation Power: 307
Facebook
The script looks fine - all it's doing is outputting the number stored in
that text file.

So what's actually the problem? Your counter is telling you that you
have had more hits on your page than you think you should have?

Where are you getting the number from Google? Are you using Adwords
and looking at the number of clicks on your ads or something?

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Javascript hitcounter over counting hits


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT