Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenX and geotargeting problem

Tags:

openx

I downloaded the latest version of OpenX 2.8.6 and I am trying to setup geotargeting, but it doesn't work. I enabled geoTargeting in administration panel ( Configuration -> Global settings -> Geotargeting module type -> OpenX Max mind (flat file) ). I read in documentation of OpenX that it's not necessary to put any path to the database in plugin settings, so I tried without. I setup delivery options of test banner to be shown only in Serbia. I am refresshing the page that displays banners, but this banner never shows.

I thought that maybe the problem is in old database and that my IP address is not recognised, so I downloaded the latest one database (.dat file) from MaxMind (lite version of Country database) and put the path in settings of the plugin, but it still doesn't work.

Can anyone help me how to resolve this problem?

like image 499
Milos Avatar asked Sep 14 '10 15:09

Milos


1 Answers

I had the same problem. It seems that OpenX since version 2.8.x is using its own php-based GeoIP-Database reader (e.g. the "flatfile" option under settings) instead of using a geoip module - which does not seem to work with current GeoIP.dat

To solve this problem I did the following:

1) open plugins/geoTargeting/oxMaxMindGeoIP/oxMaxMindGeoIP.delivery.php

2) search for:

    if (isset($GLOBALS['_MAX']['GEO_IP'])) {
        $ip   = $GLOBALS['_MAX']['GEO_IP'];
        OX_Delivery_logMessage('['.$ip.'] : ip from cookie. Plugin_geoTargeting_oxMaxMindGeoIP_oxMaxMindGeoIP_Delivery_getGeoInfo', 7);
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
        OX_Delivery_logMessage('['.$ip.'] : ip from remote addr. Plugin_geoTargeting_oxMaxMindGeoIP_oxMaxMindGeoIP_Delivery_getGeoInfo', 7);
    }
    $aGeoConf = (is_array($conf['oxMaxMindGeoIP'])) ? $conf['oxMaxMindGeoIP'] : array();

3) insert below:

$ret = array(
    "country_code" => $_SERVER['GEOIP_COUNTRY_CODE']
);
return $ret;

4) save & done

You will find possible return values in the function header:

 * @return array An array(
 *                  'country_code',
 *                  'region',
 *                  'city',
 *                  'postal_code',
 *                  'latitude',
 *                  'longitude',
 *                  'dma_code',
 *                  'area_code',
 *                  'organisation',
 *                  'isp',
 *                  'netspeed'
 *              );
 */

Read your module-doc (of mod_geoip) how to get the geo-data from current (or given) IP. In my above example I am using lighttpd 1.5 + mod_geoip (unofficial module). But this fix should also work with apache_note/pecl-geoip/mod_geoip env...

Oh and btw. its of course much faster relying on mod_geoip which caches the db in memory, than doing it all via php on every request (as openx does it).

like image 105
lifeofguenter Avatar answered Sep 26 '22 17:09

lifeofguenter