Skip to main content

Installation

tip

Be sure to follow our Javascript SDK installation instructions found here before continuing

Location detection is client side only, you can not access it via the REST API and can only be accessed via the JS SDK; however, accessing the data is very straighforward. Just load the SDK on the page, add an HTML element defined below, then register a callback method to access the data.

Define HTML

<div data-zt-type="location"></div>

Method Arguments

ArgumentRequired/OptionalTypeValue
typeRequiredstringlocation
callbackOptionalstringthe name of the method for the callback

Optional Callback

<div data-zt-type="location" data-zt-callback="myMethod"></div>
<script>
function myMethod(data) {
console.log(data);
}
</script>

Callback Response Structure

{
"zip": "USERS_ZIP_CODE"
}

Templating

You are not limited to the default location display when using our SDK. You can use a few defined template variables to adjust the display on your website. Outside of a few required variables, you are free to adjust in any way you see fit.

Template variables can be passed using the data-zt-template attribute. This attribute takes a string of bracketed reserved words which will be replaced during render with the appropriate values.

An example of templating looks like:

<div
data-zt-type="location"
data-zt-template="{TRANSLATE_ZIP_CODE} {ZIP_CODE_UPDATE_LINK} {HELP_TIP}<br />{DETECTED_LOCATION_CITY}, {DETECTED_LOCATION_STATE_CODE}"
></div>

The table below lists all available template variables used for location detection. The required template variables must be within your template string and must be available and accessible to your end user.

VariableRequired/OptionalExample ValueDescription
ZIP_CODE_UPDATE_LINKRequired90210The zip code that can be edited/updated by the end user. This field is required since users should always be allowed to update the guessed value in order to correct discrepencies.
HELP_TIPRequired(?)The help-tip that is displayed. This variable is required because it informs the user about the input box and provides required accessibility and legal information.
TRANSLATE_ZIP_CODEOptionalThe word used to designate the form field. This is typically the word 'Zip Code' in the US english language but will be translated based on region. In the UK, for instance, this would output as 'Postcode'. Some country-specific terms include ZIP code (US), PLZ (DE, AU, and CH), PIN code (IN) and CAP (IT).
DETECTED_LOCATION_CITYOptionalBeverly HillsThe city/locality of the zip code
DETECTED_LOCATION_STATE_CODEOptionalCAThe short form of the state/region name
DETECTED_LOCATION_STATEOptionalCaliforniaThe long form of the state/region name