What is the Local Storage API?
This feature is available for customers that have multiple Sites under a single domain. One common use case is for Local Pages. Once enabled, we create and store an object in the visitor's browser (using Local Storage) containing relevant information about the last Site (and any Location details - city, state, phone number, etc) they visited.
This object should then be available from any page (i.e. the Corporate Site) as long as its within the same hostname (i.e. www.yourdomain.com).

Data example

The localSiteData object is a stripped-down (does not contain all fields) JSON encoded version of our Site object.
Below is an example that contains commonly used fields.
1
{
2
"custom_fields": {
3
"example_custom_field": "More data",
4
...
5
},
6
"formatted_url": "https://www.example.com/locations/seattle/",
7
"locations": [
8
{
9
"city": "Seattle",
10
"country": "US",
11
"formatted_address": "555 Main St., Seattle, WA 98121",
12
"location_name": "Seattle Location",
13
"phonemap": {
14
"phone": "(206) 555-5555"
15
},
16
"phonemap_e164": {
17
"phone": "+12065555555"
18
},
19
"postal_code": "98121",
20
"service_areas": "Greater Seattle area",
21
"state": "WA",
22
"street": "555 Main St"
23
}
24
]
25
}
Copied!
Below are some descriptions of common use cases of this data.

Site

Accessed from the main localSiteData object
Data value
Description
custom_fields
Custom field values. Should use these with caution as they commonly change.
formatted_url
URL of the page/site they visited last

Location

Accessed from localSiteData.locations[0]
Data value
Description
formatted_address
This will be the full formatted address (street, city, state, etc) for the location that we commonly in the footer.
location_name
This is the location name
phonemap.phone
This is the display friendly version of the phone number
phonemap_e164.phone
This is the "click-to-call" formatted version of the phone number
service_areas
This is the service areas for the location

Code examples

Parsing the data

1
var localSiteData = JSON.parse(localStorage.getItem('localSiteData'));
Copied!

Check if local site data is set

If you want to first check to see if localSiteData is set before using it.
1
if (localStorage.getItem('localSiteData') === null) {
2
var localSiteData = JSON.parse(localStorage.getItem('localSiteData'));
3
4
// use this data to update the DOM
5
}
Copied!

Simple example of updating a div

Example of updating a div in the header of the page with the
1
<header class="header">
2
<div id="local-info">
3
Call YourBrand - <a href="+18005555555">1 (800) 555-5555</a>
4
</div>
5
</header>
6
7
<script>
8
if (localStorage.getItem('localSiteData') === null) {
9
var localSiteData = JSON.parse(localStorage.getItem('localSiteData'));
10
var locationData = localSiteData.locations[0];
11
document.getElementById("local-info").innerHTML = 'Call ' +
12
locationData.location_name +
13
' - <a href="' + locationData.phonemap_e164.phone + '">' +
14
locationData.phonemap.phone + '</a>';
15
}
16
</script>
Copied!
This would update the DOM with something like
1
<header class="header">
2
<div id="local-info">
3
Call Seattle Location - <a href="+12065555555">(206) 555-5555</a>
4
</div>
5
</header>
Copied!

Testing

For testing purposes, you will need to be in the same "domain" to get access to the localStorage data.
Last modified 6mo ago