Initializing the JavaScript Library

Using the init method

The init function is available under the xo , xo.activity and xo.search namespace.

Example :

  • xo.init({activity: {activityOptions}, search: {searchOptions}})

  • xo.activity.init({activityOptions})

  • xo.search.init({searchOptions})

Even if the library is called xo it's used for both FHR & XO

The activityOptions parameters are:

  1. trackerKey : your unique trackerKey to enable the tracking functions.

  2. region : the region in which your data is stored: currently only EU is available, and that's the region enabled by default.

  3. storage : optional, used to define custom storage.

The searchOptions parameters are:

  1. token: your unique Search token, available in your Console at this address.

  2. region: the region in which your data is stored. Available regions are listed below, and the default is EU.

Supported regionsCode

Europe (default)

EU

United States

US

<script type="text/javascript">
    xo.init({
        activity: {
            trackerKey: 'YOUR TRACKER KEY',
            region: 'YOUR REGION'
        }
    });
</script>

Important! To prevent possible loss of data, you should always initialize the client and identify the user before sending activities.

Once you have initialized the library, you can move on to identifying the user by following the link below.

pageManaging identities

Using custom storage

When the library is initialized, a default storage is defined. (localStorage for the browser version, or as a variable for the nodeJs version).

To use custom storage you may use the storage option as described below.

<script type="text/javascript">
    xo.init({
        activity: {
            trackerKey: 'YOUR TRACKER KEY',
            region: 'YOUR REGION',
            storage: myCustomStorage
        }
    });
</script>

This parameter takes an object with the same methods as the localStorage api (see localStorage documentation) so 4 methods:

Methoddescription

setItem(key, value)

The value to be stored and its key

getItem(key)

Return the value for given key from storage

removeItem(key)

Remove key and value from storage

clear()

Clear storage

All key, and value must be String.

Last updated