Skip to content

Datastore Module

The datastore module provides an interface to browser and server implementations for storage, managed per namespace. The module is made to be robust for a variety of storage types and implementations.

This module is available directly from the namespace:

var datastore_module = namespace.datastore();

Architecture

The datastore module contains two core components that its API builds off of: the store and the store implementations.

The store manages your storage in memory for efficient reads and writes, while not blocking the main thread while storing the data more durably. This layer will hopefully be the only one you interact with.

Behind the scenes, stores will use implementations to provide durable storage. This can be done through service workers or even directly on the main thread, depending on implementation. There's a variety of these, but the Web SDK provides three by default: memory, cookie, and local storage. By default, stores will use memory.

Stores can also keep data for a designated amount of time: pageview, visit, and user. Each datastore will clear whenever the equivalent category completes.

Info

Due to the numerous browser types and web standards, the module has the capabilities() function to provide you which capabilities are available in the current browser.

API

The datastore API wraps these components in a few simple functions to work with storage.

getStore

The getStore method should be used when you want to get a store. If the store exists, it is returned. If it does not exist, it will initialize a new one and return it.

Usage

datastore_module.getStore(name, params);

Parameters

Parameter Example Description
name
'shopper_vehicle_history'
The name to distinguish your store from others
params
{
persistenceType: 'cookie',
persistenceLevel: 'user'
}
The parameters used to configure the store.