Crownpeak
  • Product Discovery Developer Guide
  • 🛒Item catalog management
    • What is the Items API?
    • How to work with Items
      • Item Schema
        • Attributes
        • Nested Item Schemas
        • Using the Item Schema API
        • DefaultLocale API
        • Onboarding on/migrating to Fredhopper
        • List of Reserved Attributes
      • Category Tree
        • Using the Category Tree API
        • Onboarding on XO
      • Item Catalog
        • Using the Catalog API
      • Items
        • Using the streaming Items API
        • Using the batch Items API
    • Step by Step guide
      • Step by step guide for Fredhopper customers
    • Feedback
      • Using the Feedback API
    • Authorization to APIs
    • Troubleshooting API errors
  • 🎯XO Recommendations
    • Introduction
    • Using the Recommendations API
    • Setting up the Chrome extension
    • Micro-segmentation
    • XO Legacy APIs
  • 🔎XO Search
    • Introduction
    • Getting started
    • API Reference
      • Search API
      • Autocomplete API (Beta)
      • Product Suggest API
    • API Parameters
      • Search
      • Pagination
      • Faceting
      • Sorting
      • Grouping
      • Filtering
      • Disable features
      • Response mask
      • Context
    • Configuration limitation
  • 🧪A/B testing
    • Fredhopper A/B testing
      • Integration steps for a non-caching solution
      • Integration steps for a caching solution
        • Java SDK Integration
          • Setup
          • Retrieve running A/B tests - Java SDK
          • Filter and request variant - Java SDK
          • Extending the SDK
        • Manual A/B tests integration
          • Retrieve running A/B tests
          • Filter out irrelevant A/B tests
          • Assign variants to user
          • Request variant for page
        • Limitations and Best Practices
  • 📚Resources
    • Glossary
    • Best Practices
      • Tracker Best Practices
      • Items API Best Practices
      • Fredhopper Data Configuration Best Practices
      • Fredhopper Query Response Best Practices
      • Fredhopper Merchandising Studio Best Practices
    • Privacy Notice
  • Archived Pages
    • FHR Tracking plan
    • XO Tracking plan
    • The Tracking API and JS Library
      • What to Track
        • Generic Actions
          • View
          • Click
          • Add to Cart
          • Remove from Cart
          • Purchase
        • Custom Actions
      • Initializing the JavaScript Library
      • REST API Technical Documentation
Powered by GitBook
On this page
  1. Archived Pages
  2. The Tracking API and JS Library

Initializing the JavaScript Library

Using the init method

PreviousCustom ActionsNextREST API Technical Documentation

Last updated 11 months ago

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 .

  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

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

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.

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>
xo.init({
    activity: {
        trackerKey: 'YOUR TRACKER KEY',
        region: 'YOUR REGION',
        storage: myCustomStorage
    }
});
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.

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

this address
localStorage documentation