user_geo_select_region

Description

Given a list of geographic regions, selects the one in which the user has been geolocated most.

Copy
string user_geo_select_region( list regions )

Regions should be a list of four-element lists. Each inner list should contain:

  • a custom string to identify the region
  • latitude
  • longitude
  • radius, in miles
Will return the identifier string for the user’s most-visited region, or null if the user has never been identified within any of the regions. If the user has only been identified within one of the regions, the function will return the string for that region. Note: This function is only available for use with coordinates in the United States, UK, or Canada.

Example

{user_geo_select_region([['New York',40.732,-73.989,50],['London',51.385,-0.430,40]])}
Will return New York if the user has been within 50 miles of New York City, London if the user has been within 40 miles of London, or null if the user has not been identified in either of those locations.

Show a Message Based on User’s Radius from Geographic Area

Use Case: You have a message about a NYC-based event that you want to show all users who have a Sailthru geo-location tied to New York City, in that they’ve at least once been within 15 miles of its coordinates. Zephyr:
{if user_geo_select_region([['New York',40.7128,74.0059,15]]) == 'New York'}
We see you've been to New York! Next time you're there, why not check out our store on the corner of Varick and Vandam?
{/if}
Output: If user has been within 15 miles of NYC

We see you’ve been to New York! Next time you’re there, why not check out our store on the corner of Varick and Vandam?

If user has not

(no content)

Explanation: This script uses the user_geo_select_region() function to check if a user has been to a certain amount of miles of a certain region, in this instance, 15 miles of New York City’s coordinates. If they have, “New York’ is outputted. The “if” statement checks this output, and if equals “New York” (i.e. checking to see if the user has visited the area), a message prompting the user to visit a New York City based location will display. If not, that section won’t display.