Targeted content towards a specific user based on their personal information is the holy grail of website marketing. Most, if not all, large ecommerce sites have some form of targeted content implemented to make the site more relevant to its visitors.
An example of this is on Ebay.com, where they utilize this technique to display auctions on items that are similar to what the user has been searching for. By doing this, users might be compelled to keep exploring the site and ultimately buy something, which is the point.
Consider the following situation, you’re building a site where users can purchase tickets for concert events across the country. Rather than just displaying a static list of hundreds of events, why not just give the user exactly what they’re looking for by showing them events near them.
Requirements
-
Location module
-
Smart IP module
-
Views module
-
IPInfoDB account (Free)
Setup
Start by installing and activating the Location, Node Locations, Smart IP, and Device Geolocation modules. Then, select Google Maps for United States under the Geocoding Options page for the Location module(/admin/settings/location/geocoding).
Create a new content type called event . Under the Locative Information settings you’ll want to specify the Number of Locations to be at least 1 per event. Under Collection Settings set each of the location fields to “Allow”.
After signing up for a free IPInfoDB account and receiving your API key place it into the IPInfoDB Key field on the Smart IP configuration page(/admin/settings/smart_ip).
Create a new node view called nearby_events. This is what will be used to display a list of event nodes that are close to the visiting user.
You can setup the view with whatever parameters you want to display to the user. In my case, I just want to display the event title linked to the event node. After selecting your fields, filters, and sort criteria, add a new filter for Location: Distance / Proximity which will be used to display nodes within a certain distance from the user.
Use the following settings for the filter:
Paste this code in the PHP code for latitude, longitude box:
return array('latitude' => $_SESSION['smart_ip']['location']['latitude'], 'longitude' => $_SESSION['smart_ip']['location']['longitude']);
As you add events to the site, this view will display only the events within 50 miles of the visiting user whether they’re viewing on a mobile phone or a computer.