Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Test Geolocation - Support for Geocities
Test Geolocation - Support for Geocities
Test Geolocation - Support for Geocities
Hi Stephen, I am starting to use geolocation features for a module that would print the name of the city of the user to improve chances of conversion.
I created all my banners (8-9 in total) and I want first to confirm with you that that it is possible to include only one city. I only see a field for 2 letters GeoIP country code. Is it possible to do the same with GeoCity? Can the full name be written down as it appears on GA city segmentations?
Once done, I would like to test those modules using GeoCity. I was looking for a Geolocation diagnostic tester online but couldn't find any.
Any ideas?
Cheers,
Alex
Re: Test Geolocation - Support for Geocities
Hi Alex,
the GeoLiteCity database contains the full names of cities. If you have set up MetaMod to use the GeoLiteCity database, then this data is available via the variable:
$geoip->city
So in MetaMod you can use this info in an echo statement:
echo "Welcome visitor from " . $geoip->city . ".";
If you want to test on the city name, that's easy to do:
if ($geoip->city == "Glasgow") return XXX;
// replace XXX with module id to return when user is connecting from Glasgow
There's a tester online where you can enter IP addresses and see what info the GeoIP database holds on those addresses:
http://www.maxmind.com/
If you want to test whether or not your geolocation is working from different cities, it's actually a bit difficult to test. The easiest way may be to call a friend who can connect from that location and test what appears.
There are a number of web proxies based in different cities and these can be used for testing too, but the difficulty is in tracking down proxies in every city that you want to test.
Hope that helps,
Stephen
Re: Test Geolocation - Support for Geocities
Hi Stephen, it seems fine although I cannot test all city from my location. Just as a back up, I would like to add one more line, in case the module for the city doesn't return.
I would like to put an older module that can be relevent for all users. I thought of 2 ways to do it and tested it, but it doesn't work:
//Using else statements:
$mainframe =& JFactory::getApplication();
$template =& $mainframe->getTemplate();
if ( $template == "femmes_jan2011"
and $geoip->city == "Charlesbourg"){ return "450";
}
else {
return "447";
}
if ( $template == "femmes_jan2011"
and $geoip->city == "Quebec"){ return "458";
}
else {
return "447";
}
if ( $template == "femmes_jan2011"
and $geoip->city == "Beauport"){ return "459";
}
else {
return "447";
}
if ( $template == "femmes_jan2011"
and $geoip->city == "Levis"){ return "460";
}
else {
return "447";
}
if ( $template == "femmes_jan2011"
and $geoip->city == "Montreal"){ return "461";
}
else {
return "447";
}
if ( $template == "femmes_jan2011"
and $geoip->city == "Neufchatel"){ return "462";
}
else {
return "447";
}
if ( $template == "femmes_jan2011"
and $geoip->city == "Sainte-foy"){ return "463";
}
else {
return "447";
}
if ( $template == "femmes_jan2011"
and $geoip->city == "Sillery"){ return "464";
}
else {
return "447";
}
if ( $template == "femmes_jan2011"
and $geoip->city == "Vanier"){ return "465";
}
else {
return "447";
}
//Or this solution using $genius at the end of all the above without the "else" bracket:
if ( $template == "femmes_jan2011"
and $content_genius->check( "module_id not = 458,459,460,461,462,463,464,465")
return "447";
Cheers.
Alex
Re: Test Geolocation - Support for Geocities
Hi Alex,
it's just an issue of PHP logic. If you say this:
if ( A and B ) return X; else return Y;
... then it's never going to go any further. If the condition is met then it will return X. If it's not met it returns Y. Either way, it never goes any further.
I think what you are intending is more like this:
Code:
if ( A ) {
if ( B ) return X;
if ( C ) return Y;
return Z; // backstop.
}
So I'd rewrite your rule as this:
Code:
$mainframe =& JFactory::getApplication();
$template =& $mainframe->getTemplate();
$city = $geoip->city;
if ( $template == "femmes_jan2011" ) {
if ( $city == "Charlesbourg" ) return "450";
if ( $city == "Quebec" ) return "458";
if ( $city == "Beauport" ) return "459";
if ( $city == "Levis" ) return "460";
if ( $city == "Montreal" ) return "461";
if ( $city == "Neufchatel" ) return "462";
if ( $city == "Sainte-foy" ) return "463";
if ( $city == "Sillery" ) return "464";
if ( $city == "Vanier" ) return "465";
return 447;
}
Cheers,
Stephen
Re: Test Geolocation - Support for Geocities
Great it works (of course)! heh
I did a module for each template instead of coding all the template conditions in the same metamod since I wasn't sure if I needed to open another sub bracket for the next "if template = X" statement.
Thanks a bunch.
Alex.
Re: Test Geolocation - Support for Geocities
Just some thoughts on this: Part of the beauty of MetaMod is that you should be able to encapsulate all the logic inside just one MetaMod placeholder, including all the conditions, alternatives and general logic. You lose this if you just use 1 MetaMod per target module.
PHP "logic" operators are wonderful in this regard.
Cheers,
Stephen
Re: Test Geolocation - Support for Geocities
Ah OK, got it! I knew it was possible but I was just not sure how to code it for a second template.
Would it be something like this:
Code:
$mainframe =& JFactory::getApplication();
$template =& $mainframe->getTemplate();
$city = $geoip->city;
if ( $template == "femmes_jan2011" ) {
if ( $city == "Charlesbourg" ) return "450";
if ( $city == "Quebec" ) return "458";
if ( $city == "Beauport" ) return "459";
if ( $city == "Levis" ) return "460";
if ( $city == "Montreal" ) return "461";
if ( $city == "Neufchatel" ) return "462";
if ( $city == "Sainte-foy" ) return "463";
if ( $city == "Sillery" ) return "464";
if ( $city == "Vanier" ) return "465";
return 447;
}
if ( $template == "TemplateXYZ" ) {
if ( $city == "Charlesbourg" ) return "450";
if ( $city == "Quebec" ) return "458";
if ( $city == "Beauport" ) return "459";
if ( $city == "Levis" ) return "460";
if ( $city == "Montreal" ) return "461";
if ( $city == "Neufchatel" ) return "462";
if ( $city == "Sainte-foy" ) return "463";
if ( $city == "Sillery" ) return "464";
if ( $city == "Vanier" ) return "465";
return 447;
}
Cheers.
Alex
Re: Test Geolocation - Support for Geocities
Yes, that should work fine.
Something you will need to check somehow is just how the names of towns are represented in the Maxmind GeoIP databases with respect to accents. There's a list of city names at this page: http://www.maxmind.com/GeoIPCity-534-Location.csv
If you're using "==" to compare, then the strings must be EXACTLY the same, including accents, hyphens and capitalisation.
Also, bear in mind that the names of cities are often not unique. There's a Sainte-foy in France as well. If you mind about that, then you should also do a check (perhaps at the top of the rule) that the country is Canada. If it's not you could do an immediate "return".
Cheers,
Stephen
Re: Test Geolocation - Support for Geocities
Thank you Stephen, I did correct one spelling issue. I gave a try to the Coutry check at on top of my rule. I am not sure if it is good.
Code:
$mainframe =& JFactory::getApplication();
$template =& $mainframe->getTemplate();
$city = $geoip->city;
if ( $template == "electric_standard_jan2011" ) {
if ( $fromCountryId == "CA" )
return 447;
if ( $city == "Charlesbourg" ) return "450";
if ( $city == "Quebec" ) return "458";
if ( $city == "Beauport" ) return "459";
if ( $city == "Lévis" ) return "460";
if ( $city == "Montreal" ) return "461";
if ( $city == "Neufchatel" ) return "462";
if ( $city == "Sainte-foy" ) return "463";
if ( $city == "Sillery" ) return "464";
if ( $city == "Vanier" ) return "465";
return 447;
}
Maybe there's one bracket missing after the first return, or maybe the return is too soon? Please let me know...
Cheers,
Alex
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Test Geolocation - Support for Geocities
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5943
- Total Posts Today:
- 1
- User Info:
- Total Users:
- 7638
- Newest User:
- moner86658
- Members Online:
- 0
- Guests Online:
- 151
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked