Exclude self from visitors

Merchant
Depuis Netherlands
Membre depuis avr. 2015

Hi Tim, all visitors are counted now including my own, is it possible to rule out my own visits?
Bob

tim
Founder
Depuis Sweden
Membre depuis mai 2013
tim

You would have to nail your IP-address $_SERVER['REMOTE_ADDR'] in a condition inside library/lib_visitor.inc.php.

Merchant
Depuis Netherlands
Membre depuis avr. 2015

Hi Tim thanks for the prompt answer, What happens if my IP-address is dynamic?
Bob

tim
Founder
Depuis Sweden
Membre depuis mai 2013
tim

Then you have a nut case to solve ;)

Moderator
Depuis Lithuania
Membre depuis mars 2016

@tim, can you think of any other way to exclude self or better loggen admin user from being recorded if one has dynamic IP?

Merchant
Depuis Netherlands
Membre depuis avr. 2015

At the moment I rely more on analytics because LC seems to count all visitors including bots, hackers, my selves etc. And the difference is huge. Roughly 10 to 1 so for every 10 visitors only one real (possible) costumer.

Bob

Moderator
Depuis Lithuania
Membre depuis mars 2016

I'm trying avoid google products as much as possible, but thanks for the input. Maybe tim can think something out in the future if the difference is so huge.

Merchant
Depuis Netherlands
Membre depuis avr. 2015

Avoiding G products is almost impossible Knowing that we feed their knowledge of what when where and why we do something. So they can sell and make money out of it.

Very interested when you have found the golden egg Thanks Bob

Moderator
Depuis United States
Membre depuis oct. 2019

I've solved this problem, but it includes other tech besides LiteCart.

First, I created a txt file on my server and pasted my IP address into it.  Then, every morning a PHP script on my computer grabs my local IP and compares it to that file on the server.  If they're different, it uploads the new IP, overwriting the old one.  I then put code in LC's config that reads that text file and places my IP address in a global variable.

Finally, I added the following line to includes/library/lib_visitor.inc.php using a vqmod, to block my visits from being counted:
if ( strcmp( $_SERVER['REMOTE_ADDR'], MY_IP ) === 0 ) return;

This may sound like a lot, but once it's automated, you never have to touch it again.  I also have that PHP script triggered via cron throughout the day, in case my IP should change.

[b]Bonus #1[/b]: using this technique, I've also automated the writing of .htaccess files to particular directories that I want to keep private.  The IP address gets updated in those as well, locking them down to allow access only to myself.  Great for testing installs, or locking down your admin folder!

[b]Bonus #2[/b]: being that this is external from LC, you can use this setup with any other script you have, making it very versatile.

Moderator
Depuis Lithuania
Membre depuis mars 2016

Thanks for sharing. It got me some ideas, but it's not yet fully working.

Either of the code below works for admin and excludes myself from visitors, but it breaks front-end of the website.


if ( strcmp( $_SERVER['PHP_AUTH_USER'], 'admin' ) === 0 ) return;

Maybe you're smarter than me and can figure it out? :)

Moderator
Depuis United States
Membre depuis oct. 2019

Well, I don't know if I'm any smarter, but if you give us more information, I'll see what I can do.

What do you mean by "breaks the front-end"?  Is it completely blank?  Is an error given?  Are ancient Egyptian hieroglyphics printed out? :)

Where did you place that code in lib_visitor.inc.php?  I forgot to mention this in my post, but I put it right after this line:
if ($CrawlerDetect->isCrawler()) return;
In case it helps, here's my vQmod:


<modification>
<id>Don't Count Admin Visits</id>
<version>1.0</version>
<vqmver required="true">2.4.0</vqmver>
<author>s22</author>

<file name="includes/library/lib_visitor.inc.php">
<operation error="log">
<search position="after"><![CDATA[
  if ($CrawlerDetect->isCrawler()) return;
      ]]></search>
<add><![CDATA[
// ////////////////////////////
// Do not log my own visits. //
// ////////////////////////////

if ( strcmp( $_SERVER['REMOTE_ADDR'], MY_IP ) === 0 ) return;

// ////////////////////////
      ]]></add>
</operation>
</file>

</modification>```
tim
Founder
Depuis Sweden
Membre depuis mai 2013
tim

You guys are having a party here without me ;b

@s22_tech What dodo means is it will not track backend activity but won't solve it for the frontend.

@dodo how about this:

Find

include FS_DIR_APP . 'ext/CrawlerDetect/CrawlerDetect.php';
Before that, add

if (!empty(user::$data['id'])) return;
As long as you are logged in you will not be included in the stats.

Another option is to modify the graph and table, to make an exclusion of your own ip address $_SERVER['REMOTE_ADDR'].

Moderator
Depuis Lithuania
Membre depuis mars 2016

Thanks guys. This did the trick for mostly what I need:
if (!empty(user::$data['id'])) return;
Also uncommented the line below in lib_visitor.inc.php and added "Litecart" because it was also counting addons and forum posts feeds as visitors.

if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/LiteCart|bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])) return;
@bobdrinktech now I'm getting fairly accurate results. Maybe just 20-30 different from google analytics, but nowhere near the ratio of 10:1. :)

Moderator
Depuis United States
Membre depuis oct. 2019

There's also a views column in lc_products that gets incremented when I visit the front end product pages, even when I'm logged in.  This field is used in dodo's Most Sold add-on**, for example.  Here's some code for a vqmod that stops that from happening:


 <operation error="log">
 <search position="replace" offset="5" index="1"><![CDATA[
 database::query(
      ]]></search>
 <add><![CDATA[
 if ( empty(user::$data['id']) ) {
   database::query(
     "UPDATE ". DB_TABLE_PRODUCTS ."
     SET `views` = views + 1
     WHERE `id` = ". (int)$_GET['product_id'] ."
     LIMIT 1;"
   );
  }
      ]]></add>
 </operation>
 </file>```

The index="1" is required here.

** Nice mod, btw!
Vous
Ce site n'utilise aucun cookie ni aucune technologie de suivi tierce. Nous pensons pouvoir faire mieux que les autres et nous nous soucions vraiment de votre vie privée.