Geo Targeting

Discussion in 'WordPress' started by DFL, Aug 11, 2011.

  1. #1
    Hello,

    I would like to geo target US users based on their state.

    How can i do this. ( im using wordpress )
     
    DFL, Aug 11, 2011 IP
  2. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #2
    Kerosene, Aug 11, 2011 IP
  3. DFL

    DFL Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply. I downloaded both files and uploaded to my server. But im not sure what to use instead of get_country_code in your script. Would like to redirect users to another page, based on their state.

    Not the most active member, but still more than 1 post per year :D
     
    DFL, Aug 12, 2011 IP
  4. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #4
    Hmmm... looks like it's quite different using the city database than the country database.

    I just did some quick digging around the MaxMind site. Looks like you'll need geoipcity.inc for using the city database (instead of geoip.inc).
    Get it here > http://geolite.maxmind.com/download/geoip/api/php/
    Also.. this might help get it working > http://geolite.maxmind.com/download/geoip/api/php/sample_city.php

    MaxMind need some decent documentation. It's kinda hit and miss trying to get it to work, but when it does finally work, it's reasonably reliable *AND FREE*.
    There must be a simpler alternative though.
     
    Kerosene, Aug 12, 2011 IP
  5. DFL

    DFL Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    So i "constructed" a script like this. Changed country_code to city. But it will show me an error like this:

    Fatal error: Call to undefined function geoip_city_by_addr() in


    ----------

    <?
    function get_city ($ip) {
    include_once("geoipcity.inc");
    $gi = geoip_open(dirname(__FILE__)."/GeoLiteCity.dat",GEOIP_STANDARD);
    $city = (geoip_city_by_addr($gi, $ip)) ;
    geoip_close($gi);
    return $city;
    }

    $userlocation = (get_city($_SERVER["REMOTE_ADDR"]));
    echo $userlocation;
    ?>
     
    Last edited: Aug 12, 2011
    DFL, Aug 12, 2011 IP
  6. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #6
    Kerosene, Aug 12, 2011 IP
  7. DFL

    DFL Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    it shows me US USA United States NY New York Binghamton 42.1393 -75.8798 502 607, which is really very far from truth :D
     
    DFL, Aug 12, 2011 IP
  8. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #8
    So you got it running at least? Are you in the US? If not, check it from some US based proxies and see what it says.
    You may need to divert non-US traffic before they hit your US centric geo targeting page.

    :D I bet there's an easier way to do this that neither of us know about.
     
    Kerosene, Aug 12, 2011 IP
  9. DFL

    DFL Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I guess its almost working :D
    It shows the excact same location also from proxies. Im in Kuala Lumpur at the moment, so very far away from NY.
     
    DFL, Aug 12, 2011 IP
  10. DFL

    DFL Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I found a plugin for WP that uses maxmind database, so i can use codes like [mmjs-region] inside the posts. ( and its working nice this time :D )
    Can i somehow redirect users to region specific page with this info ?

    For example if NY, it will redirect to www.mydomain.com?cat=3 automatically.
     
    DFL, Aug 12, 2011 IP
  11. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #11
    What's the WP plugin?
    You should easily be able to serve up specific content using php to read the variable in the url.
    Something like...
    $category = $_GET['cat'];
    if ($category==3){echo "HELLO NEW YORK!";}
    
    PHP:
     
    Kerosene, Aug 12, 2011 IP
  12. DFL

    DFL Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    DFL, Aug 12, 2011 IP
  13. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #13
    If you can get it to echo out "HELLO NEW YORK", then you can do anything :)

    maybe something like (in the header of your WP theme)...

    $category = $_GET['cat'];
    if ($category==3){
    header('HTTP/1.1 301 Moved Permanently');
    header("Location: http://www.mydomain.com/newyork.html");
    }
    PHP:
    I haven't tried the WP plugin yet, so I'm just throwing darts out the window here :D ....
     
    Kerosene, Aug 12, 2011 IP
  14. DFL

    DFL Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    This might be a stupid question but can i do something like this: :D

    if ([mmjs-city]=New York){
    header('HTTP/1.1 301 Moved Permanently');
    header("Location: http://www.mydomain.com/newyork.html"); ?>
     
    DFL, Aug 12, 2011 IP
  15. unknownpray

    unknownpray Active Member

    Messages:
    3,831
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    70
    #15
    Google provides a local search as well as a Global search. Also you can get more specific by targeting a specific state or country and submit to a local business site. Have them list your site.
     
    unknownpray, Aug 12, 2011 IP