Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.



Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.


Using metamod, banners and geo targeting

Using metamod, banners and geo targeting


I have installed metamod and geolitecity.dat.

This is what I want to do.

I want to target my banners using Geo-targeting. So if someone can help me it would be great.

I want metamod to first look for city then region and then country.

I know how to target just one city but what is the code if I want to target more then one city. i.e. Toronto, Montreal, Ottawa.

So far I have this and it works:

if ( $geoip->city == "Toronto"   ) return "185";--I want to add Montreal and Ottawa also.

Is there a way to call banner ID instead of module ID.

It is possible that 2 or more advertisers may want to display a banner in the same city. I would like to display both banners in the same city by calling the banner ID and banners should appear in order on each page refresh. So technically speaking if there are only 2 banners in one module position then each banner should be displayed 50% of the time.

If someone can give me the code for displaying more then one banner in order (not random) that would be great.

If I am doing geo-targeting for banners, what code do I use if I want to target the world. Meaning that criteria for geo-targeting is not met but I still want a house banner to be shown.

Thank you for your help.

Beginner Modder
2 Posts
Administrator has disabled public posting

Re: Using metamod, banners and geo targeting

Any help guys would be great.

Beginner Modder
2 Posts
Administrator has disabled public posting

Re: Using metamod, banners and geo targeting

Hi Mani,

To target more than one city, use "or" in your PHP rules, like this:

if ( $geoip->city == "Toronto"  or $geoip->city == "Montreal" or $geoip->city == "Ottawa" ) return "185";

The PHP rules get run in order. So if the first line matches, and does a "return", then it never gets to the second line. In that way you can put your city rules first, followed by your region then country rules, then a "default" at the end that will catch any other location that wasn't listed earlier.

So you could do this:

if ( $geoip->city == "Toronto"  or $geoip->city == "Montreal" or $geoip->city == "Ottawa" ) return "185";
if ( $geoip->country_code == 'CA' and $geoip->region == '02' ) return 186; // British Columbia
if ( $geoip->country_code == 'US' ) return 188; // USA
return 189; // anything else that didn't already match

Note: the British Columbia region code was taken from the MaxMind site. See http://www.maxmind.com/app/fips10_4 for the regions. Note that you have to check for both country and region at the same time, as lots of countries have a region "02".

Question 2 was about doing a selection between 2 different ads. You can do it this way (random) though I see you don't want it random... oh well...

$toronto_ads = array(185, 186); // add as many as you like
$montreal_ads = array(188, 189, 190,191,192);
if ( $geoip->city == "Toronto"  ) return $toronto_ads[ mt_rand(0, count($toronto_ads) - 1) ];
if ( $geoip->city == "Montreal"  ) return $montreal_ads[ mt_rand(0, count($montreal_ads) - 1) ];

If you want them to cycle in order you can adapt the 2nd recipe from this page:
http://www.metamodpro.com/metamod/recip … er-session

Next question was about how to change just the banner id instead of the module id.

If you are using the standard Joomla Banners module then this is easy to do with MetaMod. You just use the "changes" mechanism to change the parameters of the module that you are including.

e.g. let's say that your banner module is 101, and you want to change it between category 8 and category 9 depending on the city. So you make sure that module 101 is set up correctly to start with, then do the following:

if ( $geoip->city == "Toronto"  ) $changes->mod(101)->setParam("catid",8);
if ( $geoip->city == "Montreal"  ) $changes->mod(101)->setParam("catid",9);

You can find out more about the $changes mechanism on this page:
http://www.metamodpro.com/metamod/contr … parameters

Hope that helps,

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

3330 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
Total Topics:
Total Polls:
Total Posts:
Posts this week:
User Info:
Total Users:
Newest User:
Members Online:
Guests Online:

There are no members online

Forum Legend:

 New Sticky