1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need Help with Geo-Target Banner Rotator

Discussion in 'HTML & JavaScript' started by supaH, May 18, 2013.

  1. supaH

    supaH Junior Member

    Joined:
    Nov 22, 2011
    Messages:
    123
    Likes Received:
    20
    I've looked and searched everywhere and I just can't fine a working script like this.

    What I need is a banner rotator that shows certain banners for specific countries.

    Example:
    Code:
    if (country = "US"
    {
      <img src="show US Banner"/>
    } 
    else if (country = "UK") 
    {
     <img src="show UK Banner/">
    }
    
    etc etc
    
    
    Using this: http://j.maxmind.com/app/geoip.js
    To get users country code.

    I've used and know how to do if/else scripts for java&html but I just don't understand how to find then use the visitors country in the if statement.

    This script is for CPA offers, so its important to show the right offer to the right country.

    If anyone can help me that would be awesome, I've been Googling this every which way I can think of and I just can't get it.
     
  2. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    You simply access the global functions that are created when you include the geoip javascript file:
    Code:
    var country = geoip_country_code();
    if(country==='US'){
      // do something...
    }
    else if(country==='UK'){
      // do something else...
    }
    Note: I think this implementation of Maxmind's JavaScript GeoIP API was supposed to be disabled at the beginning of the month. A new js api which requires registration and costs a lot more for larger volumes will be replacing it. You might want to look at their new one or setup your own as this probably won't be very stable.
     
  3. BIGBIGBIGMamas

    BIGBIGBIGMamas Power Member

    Joined:
    Nov 4, 2012
    Messages:
    711
    Likes Received:
    331
    Funny I was just looking for this today.
    Ever considered just using OpenX or Adzerk? Waaaay better, with alot more monetizing possibilities.
     
  4. supaH

    supaH Junior Member

    Joined:
    Nov 22, 2011
    Messages:
    123
    Likes Received:
    20
    I've managed to come up with something that actually worked. For those wondering, here is the working code I now have.
    Code:
    <html>
    <head>
    <script language="javascript" src="http://j.maxmind.com/app/country.js"></script>
    </head>
    
    <body>
    <div id="banner"></div> // Place this div where you want the banners to show
    </body>
    
    <script type="text/javascript">
    var country = geoip_country_code();
    if(country==='US'){
      document.getElementById('banner').innerHTML = '<a href="http://redirecturl" target="_blank"><img src="https://.gif" /></a>';
    }
    else if(country==='CA'){
       document.getElementById('banner').innerHTML = '<a href="hhttp://redirecturl" target="_blank"><img src="https://.jpg" /></a>';
    }
    else if(country==='UK'){
       document.getElementById('banner').innerHTML = '<a href="http://redirecturl" target="_blank"><img src="https://.gif" /></a>';
    }
    else // if none of the countries above
    {
    // Don't show a banner
    }
    </script>
    </html>
    
    I did some basic commenting on the script as well. As for using the maxmind.com javascript function, I will be on lookout for a replacement as they are probably going to disable it eventually.
     
  5. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,289
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
    do a search for geo targetting in here.. just before few days i posted a php code solution that helped another member in here.
     
  6. supaH

    supaH Junior Member

    Joined:
    Nov 22, 2011
    Messages:
    123
    Likes Received:
    20
    Ya I did search but it just gave a ton of things not relevant to what I was looking for. Also I'm much more comfortable using Javascript & Html than php.
     
  7. Felicita

    Felicita Registered Member

    Joined:
    Apr 15, 2013
    Messages:
    76
    Likes Received:
    7
    Why don't you join Adzerk, Epom or some other ad server? It's really easier, and afterall you'll get more profit with other targeting features. For example, Epom has awesome "custom targeting" feature, and if we're talking about geo targeting only - they can target even small towns! and it's free for 60 days.
     
  8. bugeast

    bugeast Junior Member

    Joined:
    Aug 21, 2015
    Messages:
    142
    Likes Received:
    16

    is this still work sir?
     
  9. docvet95

    docvet95 Junior Member

    Joined:
    Aug 10, 2010
    Messages:
    132
    Likes Received:
    199