New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin using GeoIP to accurately detect visitor countries, cities, and continent #5465

Closed
mattab opened this Issue Jan 3, 2008 · 183 comments

Comments

Projects
None yet
10 participants
@mattab
Member

mattab commented Jan 3, 2008

GeoIp Plugin
- When installed, the plugin will detect more accurately the country of your visitors using the MaxMind database.
- The existing reports for country and continent will be replaced by the more accurate GeoIp report in your Piwik interface.
- Piwik will also detect the city of your visitors. You can see all cities by clicking on the country row in the table.
- You can apply the GeoIp data to all your previous visits and re-generate your reports, see below.

Requirements

You need at least Piwik 0.2.33 to run the GeoIp plugin.

How to install?
- [Download Piwik GeoIp Plugin](http://issues.piwik.org/attachments/5465/GeoIP.zip?format=raw)
- Unzip the plugin and copy the extracted directory “GeoIp” in the directory piwik/plugins/
- Configure the MaxMind database:
– Either download MaxMind GeoLite City or GeoIP City database from http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
Uncompress this file and copy it in plugins/GeoIP/libs/GeoLiteCity.dat
– For more performance, it is recommanded to install the module apache mod_geoip.
Configure your Apache according to: http://www.maxmind.com/app/mod_geoip
- Enable GeoIP plugin in Piwik. Go to Piwik > Settings > Plugins > Geoip, click Enable

How to apply the GeoIp to all your previous visits to fix your previous reports

You can apply GeoIP precise localization on your past data:
- run geoipUpdateRows.php script, from command line (or from the browser, but risk of timing out if your database is large)
- wait a few minutes until all your visitors data from the piwik_log_visit table have been processed.
- you now need to force Piwik to re-process all the past reports: drop all piwik_archive_\* tables in your Piwik database. Piwik will automatically create them and re-process the reports.
- You should see Visitors countries and cities in your Visitors>Location report.

Authors
- Mikael Letang
- Maciej Zawadziski
- Matthieu Aubry
- Anthon Pang

Changelog
- version 0.7: cleaned up code, compatible with Piwik 0.2.33, improved documentation
- version 0.8: fixed bug in geoIpUpdateRows.php (thanks looztra)
- version 0.9: all fields now NULLable to make sure that insert still work fine after plugin is disabled
- version 0.10: compatibility with 0.2.35 after API change in the AddWidget function
- version 0.11: fixing bug with country detection
- version 0.12: updated for auto loader
- version 0.13: Compatible with Piwik 0.6
- version 0.14:
– Fixed geoipUpdateRows script which was failing with errors. It also now checks that logged in user is Super User, and that the GeoIP plugin is enabled.
– Fixed memory leak when using visitor generator.
– Fixed .htaccess was blocking users from executing the script with the browser.
– Added .htaccess to allow to execute the script directly from the browser.
– Fixed Sparkline distinct countries
- version 0.15:
– Updated for Piwik 1.3 (refactoring for upgrade.php)
– No match for country now set to ‘xx’ (unknown)
- version 0.16:
– fix bootstrap in geoipUpdateRows.php and clean-up package
– geoipUpdateRows.php – MYSQLI compatibility
– default to disk-based search; load into memory if multiple tracking requests
- version 0.17:
– fixes from peterb & mruge
- version 0.18: compatible with Piwik 1.6

Feedback

Please leave a comment if you have any feedback, suggestion, or bug report.
Keywords: third-party-plugin

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Apr 8, 2009

Thanks for the wonderful work on this plugin, it’s really great!

Just wanted to add my little contribution with a little feature I use and thought I would share.

By applying the patch ‘patch_GeoIP_0.7_google_map_link’ I just uploaded to the original tree it adds links to google maps with the location of cities in the visitor countries dropdown…

@mattab

This comment has been minimized.

Member

mattab commented Apr 14, 2009

mike5464 and rembrand, the plugin should show “Unknown” when the visitor couldn’t be located. It will only work well from the upgrade and not fix previous visits. Do you still experience the issue few days after the upgrade?

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented May 26, 2009

@rembrand:

You're using mod_geoip, right? Here's an excerpt from my apache conf:

<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPEnableUTF8 On
GeoIPOutput Env
GeoIPDBFile /path/to/GeoLiteCity.dat MemoryCache
# for mod_proxy's X-Forwarded-For
GeoIPScanProxyHeaders On
</IfModule>

Furthermore, check permissions on GeoLiteCity.dat, try chown <apacheuser> /path/to/GeoLiteCity.dat

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented May 27, 2009

wrote a small php script to test the Funktion of Geoip:

<html>
<body>
<?php
 if( !empty($_SERVER['GEOIP_COUNTRY_CODE']) )
                {
                $locationInfo = array();
                $locationInfo['country_code'] = (isset($_SERVER['GEOIP_COUNTRY_CODE'])) ? strtolower($_SERVER['GEOIP_COUNTRY_CODE']) : self::$defaultLocationInfo['country_code'];
                $locationInfo['city'] = (isset($_SERVER['GEOIP_CITY'])) ? utf8_encode($_SERVER['GEOIP_CITY']) : self::$defaultLocationInfo['city'];
                $locationInfo['latitude'] = (isset($_SERVER['GEOIP_LATITUDE'])) ? round($_SERVER['GEOIP_LATITUDE'],4) : self::$defaultLocationInfo['latitude'];
                $locationInfo['longitude'] = (isset($_SERVER['GEOIP_LONGITUDE'])) ? round($_SERVER['GEOIP_LONGITUDE'],4) : self::$defaultLocationInfo['longitude'];

                }


var_dump($locationInfo);
?>
</body>
</html>

Output : array(4) { [ string(2) "de" "city"=> string(7) "Hamburg" [ float(53.55) "longitude"=> float(10) }

Piwik still displays UserCountry_country_ for new requests...

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Jun 15, 2009

I've extended the GeoIP plugin to track in detail (In the US and Canada) which state or region the visitors are from, by adding an extra column to the database (region) and making minor changes to the code. The region can be query from the maxmind db. I was wondering if this feature can be made public?

@mattab

This comment has been minimized.

Member

mattab commented Jun 15, 2009

duylaiabc, can you please post a screenshot of how the reporting look like?

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Jun 18, 2009

it tried to get location_geoip_latitude, location_geoip_longitude from api.
I added this two columns to archiveDayAggregateVisits sql query and added

if(!isset($this->interestByCountryAndCity[$row['location_geoip_country']][$row['location_geoip_city']]['loc']))
                $this->interestByCountryAndCity[$row['location_geoip_country']][$row['location_geoip_city']]['loc']=array('lat' => $row['location_geoip_latitude'], 'lon' => $row['location_geoip_longitude']);

But the result is, most of the data have wrong lat and long values. E.g.:

    <row>
        <label>Vienna</label>
        <nb_visits>2</nb_visits>
        <nb_actions>11</nb_actions>
        <max_actions>11</max_actions>
        <sum_visit_length>330</sum_visit_length>

        <bounce_count>0</bounce_count>
        <nb_visits_converted>1</nb_visits_converted>
        <loc>
                <lat>96,4</lat>
                <lon>32,7334</lon>
        </loc>
        <sum_daily_nb_uniq_visitors>2</sum_daily_nb_uniq_visitors>
    </row>
    <row>
        <label>Leonding</label>
        <nb_visits>1</nb_visits>
        <nb_actions>17</nb_actions>

        <max_actions>17</max_actions>
        <sum_visit_length>721</sum_visit_length>
        <bounce_count>0</bounce_count>
        <nb_visits_converted>1</nb_visits_converted>
        <loc>
                <lat>48.2667</lat>

                <lon>14.2500</lon>
        </loc>
        <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors>
    </row>

as you can see, loc data of Leonding is correct, but data of Vienna isn't.
Has anybody an idea why?

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Jul 18, 2009

for people with limited memory you can replace

$this->geoIpDb = geoip_open($geoIPDataFile, GEOIP_MEMORY_CACHE);

into

$this->geoIpDb = geoip_open($geoIPDataFile, GEOIP_STANDARD);

in GeoIP.php

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Aug 25, 2009

Replying to matt:

Replying to mvanlaar:

Is it possible in future version also build a version that can lookup againt a mysql table with the data from citylite?? The file version is very slow under load. And allowing more executing time isn't (imho) a solution.

for more performance the best solution is to install the Mod GEOIP on your apache server. geoip lookups will be lightning fast!

I tested this with the MySQL version of the maxmind database (!http://ipinfodb.com/ip_database.php) and modified the plugin to perform a mysql lookup instead of the binary database and ran the update script several times. A lookup via MySQL takes about 25% longer than the current version and the mysql tables take up about 300 MB. So it's no benefit whatsoever.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Nov 24, 2009

Is this plugin still in development? I would like to use the data from this plugin to show the visitors on Google Maps (or another map service)...

@mattab

This comment has been minimized.

Member

mattab commented Dec 9, 2009

DaSilva, you are welcome to contribute to the plugin. Ideally, you would post a screenshot and a link to your example piwik with the plugin installed so we can have a look and provide Feedback. When your work is done, we can consider including it in the GeoIp plugin.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Jan 12, 2010

Replying to thibaut:

So if anybody has the possibility to craft a GeoIP version (or a working fix) that would run with 0.5.4 I (as many others I'm sure) would greatly appreciate !

I don't know what your problem is, but I have been using this plugins for months, and it is still working with 0.5.4 on my server.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Jan 19, 2010

I have all the time the "unknown" problem and sometimes "UserCountry_country_--" - but most of the time the country-detection works fine.
I tried everything :(
Same with o.5.1 - so I installad a complete new 0.5.4 with the actual GeoIP from this page and downloaded a new database-file. I followed the instruction one by one. I am sure everything is in the right directory.

Has someone some steps I could try?

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Jan 24, 2010

Replying to anamela:

Now I am using (@theodorius123 that should work for you, too!):

if(!defined('PIWIK_INCLUDE_PATH'))
{
  define('PIWIK_INCLUDE_PATH', '../../..');
}
if(!defined('PIWIK_USER_PATH'))
{
  define('PIWIK_USER_PATH', '../../..');
}

Then running the script from the command line SHOULD FUNCTION.
yes! Thank you! :)

mmh. this is not realy working for me.

857 rows to process in piwik2_log_visit...

Fatal error: error traversing database - perhaps it is corrupt? in /users/theo/www/piwik/plugins/GeoIP/libs/geoip.inc on line 422

and instead of cities i see all the time "Unknown"

:-(

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Jan 25, 2010

After installing everything except this step "For more performance, it is recommanded to install the module apache mod_geoip. Configure your Apache according to:" piwik tracks nothing anymore. After deactivation everythings works fine.

I changed all my previous reports. I've changed the PIWIK_INCLUDE_PATH to my local path in the geoipUpdateRows.php. After that change i could update all my old reports and it works fine. But the problem now is that I couldn't track any new visitor.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Feb 23, 2010

php 5.2 + mysql 5.0.X SLES 10.3 distribution.
GeoIP v0.12, piwik 0.5.4
GeoIP.php: updateExistingVisitsWithGeoIpData does not work for me. It only updates one record per each block on limit. Pretty much "while ( $row = $stmt->fetch() )" works for one record only.
Changed above line 346 "while ( $row = $stmt->fetch() )" to these two lines.
$allRows = $stmt->fetchAll();
foreach ($allRows as $row)
works fine after the change.

By the way, using geoipUpdateRows.php script from command line only.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Mar 24, 2010

Is it possible that in the archived data the latitude and longitude will be stored in the database. Would like to use this for a maps plugin.

@mattab

This comment has been minimized.

Member

mattab commented Apr 12, 2010

In Piwik 0.6, there is a backward incompatible API change in the archiving code.

All GeoIP users will need to upgrade to the latest GeoIP pluginafter they upgrade Piwik to 0.6. Piwik will automatically disable the GeoIP plugin during the upgrade to 0.6.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Apr 15, 2010

Hi, I have recently installed the latest version of Piwik .5.5 and it all works fine. I then installed Geoip and again it worked except I get the following problems...

Country (GeoIP)

UserCountry_country_ 218

and

Continent (GeoIP)

UserCountry_continent_ 218

I have looked through this thread and do not see a solution? Is there one and if so what can be done?

regards,

Blair

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Apr 23, 2010

Hi,

I developed some kind of patch to store regions more than city (I find it more practice).
You can find it here : Region display patch. Explanation in french (sorry) here : Region display explanations.

Please feel free to tell me if you see something wrong in this patch.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Apr 23, 2010

Replying to e.marguin:

Hi,

I developed some kind of patch to store regions more than city (I find it more practice).
You can find it here : Region display patch. Explanation in french (sorry) here : Region display explanations.

Please feel free to tell me if you see something wrong in this patch.
Hello,its possible to find any English version of this?
Also it's possible to redirect users from mobile/smart phones to a different page?
THanks,
Mike

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Apr 23, 2010

ok i'll just try to translate here the main things (i'm sorry by advance for my poor english)...

The geoip module gives us information about the city of visitors. But often we do not know this city because it's too small. That's why I prefer to display regions, like in the other web analyzers tools.

The patch give upper stores the region name in db instead of the city name.

To install it, just extract it into the plugin/GeoIP/ folder.
It do not update old datas. It's technically possible but I didn't need it. If anyone really wants me to write this script, I can.

Eric

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Apr 23, 2010

Replying to e.marguin:

ok i'll just try to translate here the main things (i'm sorry by advance for my poor english)...

The geoip module gives us information about the city of visitors. But often we do not know this city because it's too small. That's why I prefer to display regions, like in the other web analyzers tools.

The patch give upper stores the region name in db instead of the city name.

To install it, just extract it into the plugin/GeoIP/ folder.
It do not update old datas. It's technically possible but I didn't need it. If anyone really wants me to write this script, I can.

Eric
ok,thank you ERIC.
I will give it a try.

@mattab

This comment has been minimized.

Member

mattab commented Apr 29, 2010

mike3050, please don't add links to your websites in the trac comments, thank you.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented May 13, 2010

Hi,
I'm happily (== both from app&sys perspectives) running Piwik 0.6.1 + GeoIP using the DB file w/o mod_geoip. Found a minor (at this time) issue: Country numbers don't match with Continent numbers for Europe, where the sum is always minor than the number obtained by summing all the single countries, see below. I'm wondering if this is a bug in the code or in the lookup table.
|| Country (GeoIP) ||||
|| Country || Unique visitors ||
||Italy || 997 ||
||Unknown || 66 ||
||United States || 5 ||
||Ireland || 3 ||
||Great Britain || 3 ||
||Poland || 2 ||
||Bulgaria || 1 ||
||Russia || 1 ||
||Switzerland || 1 ||
||Germany || 1 ||

|| Continent (GeoIP) ||||
|| Continent || Unique visitors ||
||Europe || 959 ||
||Unknown || 66 ||
||North America || 5 ||

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented May 25, 2010

Replying to snowdiver:

I experience the problem, that the GeoIP data is always saved as "unknown" in the piwik_log_visit table without any city labels, latitude etc.

I installed the plugin according to your instructions above. GeoIP ver 0.13, piwik ver 0.6.1 GeoIPCity (May 2010)

Is there any hint to fix this problem?
Thanks

EDIT: Problem solved. The apache module is installed on my server, but doesn't provide enough geo-information. Switching the module-search off fixed this problem!

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented May 27, 2010

Replying to snowdiver:

EDIT: Problem solved. The apache module is installed on my server, but doesn't provide enough geo-information. Switching the module-search off fixed this problem!

sorry, i am not that fit with all these server, php, etc stuff. i am using piwik and geoip and have the same "unknown" problem. but i dont have an own server, my homepage is on a freehoster-server (bplaced.net). is it possible to do what you did when i am using a free-hoster??

thanks!
theo

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented May 30, 2010

Replying to theodorius123:

Replying to snowdiver:

EDIT: Problem solved. The apache module is installed on my server, but doesn't provide enough geo-information. Switching the module-search off fixed this problem!

sorry, i am not that fit with all these server, php, etc stuff. i am using piwik and geoip and have the same "unknown" problem. but i dont have an own server, my homepage is on a freehoster-server (bplaced.net). is it possible to do what you did when i am using a free-hoster??

thanks!
theo

My homepage is also hosted on bplaced.net servers, so we met the same problem. It is just a small modification of the GeoIP.php file. Just remove or comment lines 230-234 to force the plugin to use the GeoLiteCity.dat file instead of the Apache Module, which in the bplaced.net case does not provide information about the city of a visitor.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Jun 24, 2010

The most frequent "city" in my stats is "unknown". Any suggestion for a better geoip database? I'm concerned only with Brazil, FWIW.

@mattab

This comment has been minimized.

Member

mattab commented Jun 29, 2010

All users experimenting issues with the geoipUpdateRows.php script, we have fixed a few bugs reported by users in this thread. Check out the new GeoIP 0.14 version.

If you still have issues, please report here, we'll do our best to fix it.

Users that are seeing a lot of 'unknown' countries and cities, this is probably due to the low coverage of the Free IP to country database provided by MaxMind. If anyone knows a better DB, let us know! You can alternatively buy the MaxMind pro DB, but I haven't tested how accurate this DB is.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Aug 27, 2012

I have it installed on Apache 2.2.17 and it works fine.
:-)

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Aug 27, 2012

Suggeston to add:

$view->disableRowEvolution();

in row 51 in GeoIP/Controller.php
This will hide the Row Evolution feature on the Country and Continent table since it is currently not implemented.

Providers table will still have Row Evolution function

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Aug 27, 2012

@mcantsin this plugin is working for me and many others, are you sure mod_geoip is active and configured?
Create a file and name it for example geoiptest.php with the following content:

<?php
    header('Content-type: text/plain');
    print_r($_SERVER);
?>

Then access that file via your webserver http://yourserver.com/geoiptest.php

Now you should have a couple of replies that states GEOIP information, for example:

    [GEOIP_CONTINENT_CODE] => EU
    [GEOIP_COUNTRY_CODE] => SE
    [GEOIP_COUNTRY_NAME] => Sweden
    [GEOIP_REGION] => 26
    [GEOIP_REGION_NAME] => Stockholms Lan

if that is not working go to the link above http://dev.maxmind.com/geoip/mod_geoip2 and make sure the .dat file is in the right folder and readable for the webserver

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Aug 28, 2012

Hmm, i found there is a Problem with the install process. When i run the geoipUpdateRows.php i get this error

PHP Fatal error:  Uncaught exception 'Zend_Db_Statement_Mysqli_Exception' with message 'Mysqli prepare error: Unknown column 'location_geoip_region' in 'field list'' in /home/www/piwik/libs/Zend/Db/Statement/Mysqli.php:77

There is a field missing and we have a php error. So nothing is logged to Piwik with GeopIP is enabled.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Aug 30, 2012

@greg I added the following line in GeoIP.php so it handles live visitors on my install.
Row 280

        $locationInfo['region'] = (isset($_SERVER['GEOIP_REGION'])) ? $_SERVER['GEOIP_REGION'] : self::$defaultLocationInfo['region'];

@ManuelW it appears you are running the latest GeoIP without the install() function being run, I don't know how to force it to reinstall but if you know how to add SQL columns run this:

ALTER TABLE `piwik_log_visit` ADD `location_geoip_region` VARCHAR(2) NULL;
@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Aug 30, 2012

Attachment: 0.18 with minor changes (disabled row evolution, region changes by greg)
GeoIP.2.zip

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Aug 30, 2012

Replying to dbmz:

@greg I added the following line in GeoIP.php so it handles live visitors on my install.
Row 280

      $locationInfo['region'] = (isset($_SERVER['GEOIP_REGION'])) ? $_SERVER['GEOIP_REGION'] : self::$defaultLocationInfo['region'];

is it added in the new GeoIP.2.zip also?

@ManuelW it appears you are running the latest GeoIP without the install() function being run, I don't know how to force it to reinstall but if you know how to add SQL columns run this:

ALTER TABLE `piwik_log_visit` ADD `location_geoip_region` VARCHAR(2) NULL;

Thanks for the hint. Thats what i've done yesterday and would report now :D it works

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Aug 30, 2012

Replying to ManuelW:

Replying to dbmz:

@greg I added the following line in GeoIP.php so it handles live visitors on my install.
Row 280

        $locationInfo['region'] = (isset($_SERVER['GEOIP_REGION'])) ? $_SERVER['GEOIP_REGION'] : self::$defaultLocationInfo['region'];

is it added in the new GeoIP.2.zip also?

Yes it is in there.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Sep 7, 2012

When GeoIP is enabled as an Apache module GeoIP won't work. It throws a Fatal Error like so:
PHP Fatal error: Cannot redeclare geoip_country_code_by_name() in /is/htdocs/wpxxx/xxx/piwik/plugins/GeoIP/libs/geoip.inc on line 347

My hosting provider is Hosteurope. I'm on a shared hosting there (Webpack L).
They have changed their server settings yesterday.

Hopefully there is a solution soon.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Sep 10, 2012

As far as I know it is not possible for apache modules to declare PHP functions. It is possible that someone at your shared host is autoloading the geoip functions, to check create a new file get_defined_functions.php with the following content

<?php
    header('Content-type: text/plain');
    print_r(get_defined_functions());
?>

access it via your webbrowser and search for the function there, pay extra attention to functions under the "user" tag. I'm not very familiar with autoloading functions, is piwik installed as a seperate site (VirtualHost) in your apache config?

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Sep 12, 2012

I have a weird problem.
At the overview I see Visitors from germany, if I expand germany I see vities from Polen. The same with UK, there I see just cities from France.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Sep 12, 2012

I patched GeoIP plugin to fix bug in live data.
All you have to do is to find this in GeoIP.php

$mappingVisitorInfoToGeoIp = array(
'location_geoip_country' => 'country_code',
'location_geoip_continent' => 'continent',
'location_geoip_city' => 'city',
'location_geoip_latitude' => 'latitude',
'location_geoip_longitude' => 'longitude',
);

and add

'location_country' => 'country_code',
'location_continent'=> 'continent'

If you also want to modify your old data, update "updateExistingVisitsWithGeoIpData" method. Again, you only have to change Piwik_Query to

"
UPDATE ".Piwik_Common::prefixTable('log_visit')." 
SET location_geoip_country = ?, 
location_geoip_continent = ?, 
location_geoip_city = ?, 
location_geoip_latitude = ?, 
location_geoip_longitude = ?,
location_country =?,
location_continent = ?
WHERE idvisit = ?", 
array(  $locationInfo['country_code'],
$locationInfo['continent'],
$locationInfo['city'],
$locationInfo['latitude'], 
$locationInfo['longitude'], 
$locationInfo['country_code'],
$locationInfo['continent'],
$row['idvisit']

And the whole thing will work :)

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Sep 16, 2012

@dbmz
maybe Iyou're right and I was mistaken by the phpinfo() output that I got.
Maybe you'ld like to check it yourself ... they have a copy here:
[http://www.hosteurope-infos.de/phpinfo.php].

The script that you suggested outputs geoip functions in the 'internal' array like this:

[ 1278 ] => geoip_database_info
[ 1279 ] => geoip_country_code_by_name
[ 1280 ] => geoip_country_code3_by_name
[ 1281 ] => geoip_country_name_by_name
[ 1282 ] => geoip_continent_code_by_name
[ 1283 ] => geoip_org_by_name
[ 1284 ] => geoip_record_by_name
[ 1285 ] => geoip_id_by_name
[ 1286 ] => geoip_region_by_name
[ 1287 ] => geoip_isp_by_name
[ 1288 ] => geoip_db_avail
[ 1289 ] => geoip_db_get_all_info
[ 1290 ] => geoip_db_filename
[ 1291 ] => geoip_region_name_by_code
[ 1292 ] => geoip_time_zone_by_country_and_region

My piwik installation is not an extra host. it's just a site's subdirectory.

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Sep 19, 2012

Since I have updated PIWIK to 1.8.4 I do not see any city information in the visitors log. Any idea?

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Oct 3, 2012

Please make available a single always up-to-date zip file mortals can download and install without headaches form patches, updates, and so on :)

It would be very nice to have the main download always point to this latest release. Thank you in advance.

@mattab

This comment has been minimized.

Member

mattab commented Oct 3, 2012

In the next 1.9 release, GeoIP will be included in Piwik by default. See #1823

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Oct 5, 2012

Very good news :) thank you

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Oct 29, 2012

Dear all,

I am using piwik 1.4 ,I have configured it according to my database.
As of now i get the visitor information from countries only.
I want to narrow it down to state and cities and so on....!

I followed these steps
1.Download Piwik GeoIp Plugin
2.Unzip the plugin and copy the extracted directory "GeoIp" in the directory piwik/plugins/
Configure the MaxMind database:
3. download MaxMind GeoLite City or GeoIP City database from http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz Uncompress this file and copy it in plugins/GeoIP/libs/GeoLiteCity.dat

In my configuted piwik i am not getting any setting option and i couldnt do "Enable GeoIP plugin in Piwik. Go to Piwik > Settings > Plugins > Geoip, click Enable"

one more query
How are we using the map here??
Is it a .swf file and Js is interactig with it OR something else ??

For the GeoIp we are using .swf or someother file??

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Oct 29, 2012

Did you install the host files ?

You can find them from Europe here
http://www.hosteurope-infos.de/phpinfo.php

Kinde regards
Gavekort

Replying to rajkisho:

Dear all,

I am using piwik 1.4 ,I have configured it according to my database.
As of now i get the visitor information from countries only.
I want to narrow it down to state and cities and so on....!

I followed these steps
1.Download Piwik GeoIp Plugin
2.Unzip the plugin and copy the extracted directory "GeoIp" in the directory piwik/plugins/
Configure the MaxMind database:
3. download MaxMind GeoLite City or GeoIP City database from http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz gavekort skabelon Uncompress this file and copy it in plugins/GeoIP/libs/GeoLiteCity.dat

In my configuted piwik i am not getting any setting option and i couldnt do "Enable GeoIP plugin in Piwik. Go to Piwik > Settings > Plugins > Geoip, click Enable"

one more query
How are we using the map here??
Is it a .swf file and Js is interactig with it OR something else ??

For the GeoIp we are using .swf or someother file??

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Nov 1, 2012

Thanks...I have sorted out that issue.

Next query is as follows:
When i go to ,Visitors->Locations

I see 3 colors
Red for the country having highest numberofvisits
Dark Yello for the country having second highest numberofvisits
yello for others....

I want in the Piwik files..where this color configration is done ??

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Nov 14, 2012

After the plugin was added to the core, the old table rows can be deleted to clean the database a bit, right?

As I do not want to delete the wrong rows or just some of the rows, what exactly can I delete?

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Nov 15, 2012

What about my question from yesterday about the old table rows which can be deleted from the database?

@anonymous-piwik-user

This comment has been minimized.

anonymous-piwik-user commented Feb 11, 2014

Can I override GeoIP with custom data? For example I have an organization with many offices and subnets and I want to see those office locations in Piwik, based on my defined subnet=location data. Maxmind doesn't have these details. Or should I post this as a feature request?

@BeezyT

This comment has been minimized.

Member

BeezyT commented Feb 11, 2014

You can write a custom plugin that hooks into Tracker.saveVisitorInformation, checks whether location_ip is in your subnet and overrides the other location_* attributes of the visitor information.

This ticket is not the right place for questions like this. If you want further free support, you can use our forums. If you want paid support (e.g. the development of such a plugin), you can contact services] or me via timo at piwik.org.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment