> For the complete documentation index, see [llms.txt](https://fredhopper.gitbook.io/product-discovery/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fredhopper.gitbook.io/product-discovery/resources/archived-pages/the-tracking-api-and-js-library/initialize-the-library.md).

# 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})`

{% hint style="info" %}
Even if the library is called xo it's used for both FHR & XO
{% endhint %}

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](https://console.early-birds.io/#/search/token).
2. `region`: the region in which your data is stored. Available regions are listed below, and the default is **EU**.

| Supported regions    | Code     |
| -------------------- | -------- |
| **Europe (default)** | **`EU`** |
| United States        | `US`     |

{% tabs %}
{% tab title="inline HTML" %}

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

{% endtab %}

{% tab title="Javascript" %}

```javascript
xo.init({
    activity: {
        trackerKey: 'YOUR TRACKER KEY',
        region: 'YOUR REGION'
    }
});
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Important!** To prevent possible loss of data, you should always initialize the client **and** identify the user before sending activities.
{% endhint %}

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

{% content-ref url="<https://github.com/Attraqt/product-discovery-documentation/blob/main/new-docs/Archive/the-tracking-api-and-js-library/broken-reference/README.md>" %}
<https://github.com/Attraqt/product-discovery-documentation/blob/main/new-docs/Archive/the-tracking-api-and-js-library/broken-reference/README.md>
{% endcontent-ref %}

## 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.

{% tabs %}
{% tab title="HTML" %}

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

{% endtab %}

{% tab title="NodeJS" %}

```
xo.init({
    activity: {
        trackerKey: 'YOUR TRACKER KEY',
        region: 'YOUR REGION',
        storage: myCustomStorage
    }
});
```

{% endtab %}
{% endtabs %}

This parameter takes an object with the same methods as the `localStorage` api (see [localStorage documentation](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)) so 4 methods:

| Method                | description                                     |
| --------------------- | ----------------------------------------------- |
| `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.
