antonioribeiro / tracker

Laravel Stats Tracker
MIT License
2.89k stars 593 forks source link

geoip no data available #200

Open Cate2 opened 8 years ago

Cate2 commented 8 years ago

Hi, I want to ask, if anybody know, where could be a problem, because in tracker_geoip table aren't any data. For example in table tracker_agents are data. In config I have 'log_geoip' => true and I have installed "geoip2/geoip2":"~2.0"

Thank you

Cate2 commented 8 years ago

And for example, I have / * Do you wish to log the user agent? / 'log_user_agents' => false, and i have data about user agents in my database anyway, co It's look like it's ignore config.php

m7vm7v commented 7 years ago

What is the respond of this: $visitor = Tracker::currentSession(); dd($visitor->geoIp);

KwanYX commented 7 years ago

i have same problem and respond of dd($visitor->geoIp); is null @antonioribeiro @m7vm7v

LMCom commented 7 years ago

Looks like a bug in the code.

When Tracker is trying to retrieve GeoIp data, it finally calls the private method databaseExists() in https://github.com/antonioribeiro/support/blob/master/src/GeoIp/GeoIp.php#L21. If the database does not exist, nothing happens. This silent failure was introduced by commit https://github.com/antonioribeiro/support/commit/776b3e63171161cf0e17fff240f90547aed8646c#diff-fdd42cf520dfaffd4c4d3a0018feb14c. Before that, it likely threw an exception and people figured out what to do. However, the readme file of this project does not tell anything about the requirement of a database file for GeoIp functionality.

Further investigation reveals that the private property databasePath of GeoIp can only be set via its constructor. However, https://github.com/antonioribeiro/tracker/blob/master/src/Vendor/Laravel/ServiceProvider.php#L257 creates an instance of GeoIp without specifying databasePath. So it's to be expected that any attempt to retrieve GeoIp fails silently.

LMCom commented 7 years ago

The following fixed it for me, based on my previous findings.

Go to https://dev.maxmind.com/geoip/geoip2/geolite2/ and download the databases GeoLite2 City/Country in the MaxMind format. Copy them both into the same directory of your choice. A quick hack of https://github.com/antonioribeiro/tracker/blob/master/src/Vendor/Laravel/ServiceProvider.php#L258 to instantiate GeoIp with the path to the database files enables geo ip logging. Now, I will implement a cleaner fix for my app by overloading RepositoryManager.

@Cate2 @antonioribeiro @m7vm7v @KwanYX

antonioribeiro commented 7 years ago

Tagged Tracker 3.2.2. You should now have access to the command

php artisan tracker:updategeoip

image

You also add to config/tracker.php the GeoIP database path:

'geoip_database_path' => storage_path('geoip'),

Let me know if it works for you.

LMCom commented 7 years ago

Ha! In the meantime I wrote my own command to pull the geo ip databases. And using a config setting to instantiate GeoIp with the correct path, was exactly what I would have done, too. Great minds think alike. ;)

Thanks for the quick coding.

Let me know if it works for you.

It works and I got rid of my hacks. :)

kabircse commented 6 years ago

It is not working for me. Just geoip is not saving data. What can I do?

emadrashad commented 6 years ago

@antonioribeiro man u could be our saver here , using laravel 5.6 and geoip v2 it's always null i walked with all issues , performed what u did exactly , am using windows 10 screencapture-127-0-0-1-8000-1520436154043

tornadofay commented 6 years ago

any solution for this problem ?

tornadofay commented 6 years ago

sorry i get it to work finally by following this https://github.com/antonioribeiro/tracker/issues/130

osman-mohamad commented 6 years ago

when I run php artisan tracker:updategeoip I see error There are no commands defined in the "tracker" namespace.


the error accour when the tracker is disabled .

meeprakash25 commented 6 years ago

@tornadofay tornadofay how did you solve this problem can you please explain, the link you provided didn't help

tornadofay commented 6 years ago

here is how i configured it: first install geoip2/geoip2

in config\app.php

* Package Service Providers
PragmaRX\Tracker\Vendor\Laravel\ServiceProvider::class,
* Class Aliases
'Tracker' => PragmaRX\Tracker\Vendor\Laravel\Facade::class,

in config\tracker.php

return [
'enabled' => true,  //--> important 
'cache_enabled' => true,
'use_middleware' => true,
'log_enabled' => true,
'connection' => 'tracker',
'log_geoip' => true, //--> important 
'geoip_database_path' => storage_path('app/geoip'),  //--> important 
'geoip_model' => 'PragmaRX\Tracker\Vendor\Laravel\Models\GeoIp', //--> important 
.
. 

in app\Http\Kernel.php add

protected $middlewareGroups = [
        'web' => [
                          \PragmaRX\Tracker\Vendor\Laravel\Middlewares\Tracker::class,

after that run php artisan config:cache <---- if on production php artisan tracker:updategeoip <----- will take some time to download database but it work after

@meeprakash25 hope this help solve the problem,

meeprakash25 commented 6 years ago

Thank you so much I'll try it and let you know if it worked

meeprakash25 commented 6 years ago

@tornadofay is that geoip_database_path correct?

tornadofay commented 6 years ago

@tornadofay is that geoip_database_path correct?

sorry for late reply, yes I copied it from config\tracker.php

/*
     * GeoIp2 database path.
     *
     * To get a fresh version of this file, use the command
     *
     *      php artisan tracker:updategeoip
     *
     */
    'geoip_database_path' => storage_path('app/geoip'),

also you may need to take look into Torann\GeoIP, if it still not working.

ionesculiviucristian commented 5 years ago

I think is related to using localhost. If u uncomment the ip range (local) in the tracking.php config file the geoip object will not gather the data required.