user_geo_home

Welcome to our newly overhauled Zephyr pages! See our new Overview, Examples, and Index.
Feedback is welcome at bottom of each page.

Description

Returns the most frequent location of your user based on Sailthru’s geolocation data.

 mixed user_geo_home( string geo_field )
  • The geo_field specifies which form of geolocation data you want returned.
    The valid options are: city, country, state, zip, postal, and coordinates.

    • city, country, state, zip, and postal will all return their values as a string.
    • coordinates will return an array with the latitude and longitude of the most common ZIP/postal code in the format [latitude, longitude].

Examples

{user_geo_home("state")}

Returns NY US

{user_geo_home("zip")}

Returns 10010 US

{user_geo_home("coordinates")}

Returns [40.712, -74.005]

Dynamic Message Based on Geolocation

Use Case: You want to use Sailthru’s geo-tracking to determine where users are located in order to show them location-based content, like events or brick-and-mortar locations.

Zephyr:

{if user_geo_home("city") == "New York, NY US"}
<!--HTML for New York City location goes here-->
{else if user_geo_home("city") == "Los Angeles, CA US"}
<!--HTML for LA location goes here-->
{else}
<!--HTML for default content here-->
{/if}

Explanation: This script uses the user_geo_home() function to display dynamic content based on Sailthru-tracked geolocation, which is captured at point of click through an email. If the user’s geolocated city is New York, NY US, it will show New York-based content. If it’s Los Angeles, CA US, it will show Los Angeles content. Otherwise, it’ll show default content.

Display Content from a Feed Based on a User’s Geolocation

Use Case: You’re using the sailthru.location meta tag to place latitude and longitude on your content, and you want to only display content if the user is geo-located within 20 miles of that item.

Zephyr:

{**Creates an array of user lat/long, coords[0] being lat, coords[1] being long**}
{coords = user_geo_home("coordinates")}
Stories in Your Neighborhood:
{foreach content as c}
  {if contains(c,c.location)}
      {if distance(c.location[0], c.location[1], coords[0], coords[1]) > 20}
<a href="{c.url}">{c.title}<a/> ({round(distance(c.location[0],c.location[1],coords[0],coords[1]))} from you!) <br/>
{/if}
  {/if}
{/foreach}

Output:

Stories in Your Neighborhood:

(New York City based user):

Get Your First Look at the New iPhone at the Times Square Apple Store (2.1 miles you from!)

Spider-Man: Threat or Menace? (7.2 miles from you!)

(Los Angeles based user):

Alexander Harris elected to Los Angeles House of Representatives (12.8 miles from you!)

Explanation:

This script uses the user_geo_home() function to find the coordinates of a user’s Sailthru-tracked geolocation (obtained at point of click through an email). It then assigns this value to a local variable called “coords,” which is an array of the user latitude (position 0) and longitutde (position 1). Next, a foreach loop iterates through each piece of content from a data feed and, using an “if statement”, uses the contains() function to see if each content has the “location” parameter. If it does, using a second “if” statement, the script uses the distance() function to check if if the content’s latitude/longitude (c.location[0] and c.location[1] is within the user’s latitude/longitude (coords[0] and coords[1]. If the statement evaluates to true, the title and URL will populate and display to the user.

The script also uses the round() function to tell the user how close they are from the story. The distance from the user is calculated the same as before (using the item’s coordinates evaluated against the user’s), but the actual distance is rounded to the nearest decimal point in order to display a user-friendly version of how close the user is.

Top