---
title: Initialize the Coveo UA library
slug: l2bf0354
canonical_url: https://docs.coveo.com/en/l2bf0354/
collection: coveo-for-commerce
source_format: adoc
---
# Initialize the Coveo UA library
> **Important**
>
> We strongly recommend that all new Commerce implementations use the [Event Protocol](https://docs.coveo.com/en/o1n91230/) to log events.
You must include the following script tag to load the [Coveo UA library](https://www.npmjs.com/package/coveo.analytics) into your page.
The first parameter is always a command name, and the other parameters vary depending on the executed command.
The `init` command is used to initialize the script and **must** be called **once** on each page.
```html
```
<1> [Global fields](#global-fields)
<2> [Tracking ID](#tracking-id)
<3> [User Authentication](#user-authentication)
<4> [Coveo UA endpoint](#coveo-ua-alternate-endpoints)
<5> [`userId` (optional)](https://docs.coveo.com/en/l29e0540#userid-string)
## Global fields
Some commands allow setting data where fields parameters can be set for the entire page.
Fields can be set with `coveoua("set", , )`.
For reference information, see [Global fields references](https://docs.coveo.com/en/l29e0540#global-fields-reference).
### Set the currency code
In the script in the introduction, replace `` with the three-letter currency code following the [ISO 4217 standard](https://www.iso.org/iso-4217-currency-codes.html) to identify a user's currency.
For example, if you initialize the library on a page that serves European users, you would enter `coveoua('set', 'currencyCode', 'EUR')`.
## Tracking ID
A [Coveo organization](https://docs.coveo.com/en/185/) can serve many Coveo-powered commerce sites or applications, but all [Coveo Analytics events](https://docs.coveo.com/en/260/) in a user's journey should be tied together with a single tracking ID for accurate data analytics and consistency.
[tracking IDs](https://docs.coveo.com/en/o8rb0139/) segregate the data gathered from each of these sites or applications to ensure personalized and relevant output from your [Coveo Machine Learning (Coveo ML)](https://docs.coveo.com/en/188/) [models](https://docs.coveo.com/en/1012/), usable [reporting](https://docs.coveo.com/en/266/), and clear merchandising actions.
Each tracking ID points to a specific ecommerce [storefront](https://docs.coveo.com/en/p33g0410/), creating a way to distinguish between distinct sites and their respective user journeys.
The tracking ID is defined when sending events to the [Coveo Platform](https://docs.coveo.com/en/186/).
Interfaces built with the Coveo [Headless library](https://docs.coveo.com/en/lcdf0493/) or [Atomic library](https://docs.coveo.com/en/lcdf0264/) automatically include the tracking ID in the events they send.
While tracking ID values are specified when sending [Coveo Analytics events](https://docs.coveo.com/en/260/), each value that's sent must be registered using a [**Property**](https://docs.coveo.com/en/o7vh0012/) in your [Coveo organization](https://docs.coveo.com/en/185/).
To learn how to map your [storefront](https://docs.coveo.com/en/p33g0410/) architecture and use tracking IDs in Coveo for Commerce, refer to the [Coveo for Commerce setup guide](https://docs.coveo.com/en/o25a0034/).
**Example**
Your [Coveo organization](https://docs.coveo.com/en/185/) powers two brands: **Barca sports** and **Barca parts**.
You operate in two different countries: **United States** and **Canada**.
Therefore, you have four different sites that require their own unique tracking ID to be sent with each event:
* `barca_sports_us`
* `barca_sports_ca`
* `barca_parts_us`
* `barca_parts_ca`
Each of these tracking IDs is registered using a property in your [Coveo organization](https://docs.coveo.com/en/185/) to ensure that the data is correctly sent:
* **Barca Sports US**
* **Barca Sports CA**
* **Barca Parts US**
* **Barca Parts CA**
> **Important**
>
> * The `trackingId` parameter can only contain lowercase letters, numbers, underscores (`_`), hyphens (`-`), and periods (`.`).
> For example, the following tracking IDs would be valid:
>
> ** `barca_sports1_us`
>
> ** `barca-sports1-us`
>
> ** `barca.sports1.us`
>
> * A single user journey can't span multiple tracking IDs, and [Coveo Analytics data](https://docs.coveo.com/en/259/) is segregated by tracking ID.
> When you analyze metrics like views, clicks, or conversions, the [Advanced Reports](https://docs.coveo.com/en/lbtf7260/) will show them for each tracking ID.
>
> * Tracking IDs shouldn't be confused with other factors such as the site's domain, [locale](https://docs.coveo.com/en/p4tf0351/), or catalog ID.
In the script in the introduction, replace `` with your [tracking ID](https://docs.coveo.com/en/o8rb0139/) to ensure that analytics across multiple digital experiences are properly tracked.
## User authentication
In the script in the introduction, replace
`` with an [API key](https://docs.coveo.com/en/105/) that was created using the **Anonymous search** [template](https://docs.coveo.com/en/1718#api-key-templates) or a [search token](https://docs.coveo.com/en/56/) that grants the **Push** [access level](https://docs.coveo.com/en/2818/) on the [**Analytics Data**](https://docs.coveo.com/en/1707#administrate-domain) [domain](https://docs.coveo.com/en/2819/) in the target [organization](https://docs.coveo.com/en/185/).
To use that same search token for your [search interface](https://docs.coveo.com/en/2741/) as a whole, also grant it the **Allowed** [access level](https://docs.coveo.com/en/2818/) on the [**Execute Queries**](https://docs.coveo.com/en/1707#execute-queries-domain) [domain](https://docs.coveo.com/en/2819/) privilege.
:leveloffset!:
## Coveo UA alternate endpoints
To log [Coveo Analytics events](https://docs.coveo.com/en/260/) for an [organization](https://docs.coveo.com/en/185/), ensure that you set the Coveo [`endpoint`](https://coveo.github.io/search-ui/components/analytics.html#options.endpoint) option of your desired [`Analytics`](https://coveo.github.io/search-ui/components/analytics.html) component.
Otherwise, the default production endpoint (`prod-us`) will be used and you won't benefit from your [organization-specific analytics endpoint](https://docs.coveo.com/en/mcc80216#analytics-endpoint).
When initializing the library, replace `` in the script with the Coveo Platform endpoint for your organization.
[%header,cols="2"]
|===
|Coveo
|Endpoint
|prod
|`+https://.analytics.org.coveo.com+`
|[HIPAA](https://docs.coveo.com/en/1853/)
|`+https://.analytics.orghipaa.coveo.com+`
|===
Where `` is the [unique identifier of your Coveo organization](https://docs.coveo.com/en/n1ce5273/).