Gathering detailed insights and metrics for coveo.analytics
Gathering detailed insights and metrics for coveo.analytics
Gathering detailed insights and metrics for coveo.analytics
Gathering detailed insights and metrics for coveo.analytics
npm install coveo.analytics
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
10 Stars
1,311 Commits
13 Forks
12 Watching
3 Branches
57 Contributors
Updated on 29 Oct 2024
TypeScript (96.3%)
HTML (2.42%)
JavaScript (1.08%)
Dockerfile (0.19%)
Cumulative downloads
Total Downloads
Last day
9.5%
4,081
Compared to previous day
Last week
2.1%
21,200
Compared to previous week
Last month
-2.6%
94,920
Compared to previous month
Last year
19.8%
1,174,797
Compared to previous year
35
The Coveo analytics javascript client, also called coveo.analytics.js or coveoua for short, is responsible for logging analytics events to the Coveo platform. Analytics events may include basic Coveo web events such as clicks or searches. For specific usecases, such as commerce and service, dedicated events may be defined and logged.
The analytics library is bundled with all Coveo provided UI components. Integrations which exclusively rely on these components, generally don't have to interact with coveoua directly. For Coveo integrations which integrate with an already existing UI and do not use headless, coveoua will be required to ensure events are logged correctly.
In order to ensure the tracking code is available on your webpage, the following code snippet needs to be added to the top of each page on which analytics are required. This will load the latest major version of coveo.analytics.js from a Coveo CDN. As of writing, the current major version is 2.
1<script> 2 (function (c, o, v, e, O, u, a) { 3 a = 'coveoua'; 4 c[a] = 5 c[a] || 6 function () { 7 (c[a].q = c[a].q || []).push(arguments); 8 }; 9 c[a].t = Date.now(); 10 u = o.createElement(v); 11 u.async = 1; 12 u.src = e; 13 O = o.getElementsByTagName(v)[0]; 14 O.parentNode.insertBefore(u, O); 15 })(window, document, 'script', 'https://static.cloud.coveo.com/coveo.analytics.js/2/coveoua.js'); 16</script> 17 18coveoua('init', #COVEO_API_KEY); // Replace #COVEO_API_KEY with your api key
Since calls to the coveo analytics service need to be authenticated, the library needs to be initialized with a Coveo api key which has push access to the Analytics Data Domain. You can create an API key from the administration console selecting the Push option box for the Analytics Data domain (see Adding and Managing API Keys).
After the library has loaded sucessfully, you can interact with coveoua through the global coveoua
function. Any interaction with the library happens through this function by supplying both a action name, followed by an optional series of action arguments. The following actions are available:
coveoua('version')
: Returns the current version of the tracking library.coveoua('init', <COVEO_API_KEY>, <ENDPOINT>)
: Initializes the library with the given api key and endpoint. The following parameters are accepted
coveoua('init', <COVEO_API_KEY>, {endpoint: <ENDPOINT>, isCustomEndpoint: <IS_CUSTOM_ENDPOINT>, plugins: <PLUGINS>})
: Initializes the library with the given api key, endpoint, isCustomEndpoint option and plugins. The following parameters are accepted
coveoua('set', <NAME>, <VALUE>)
: Attempts to inject an attribute with given name and value on every logged event, overriding any existing value. Some payloads may reject attributes they do not support.coveoua('set', <OBJECT>)
: Attempts to inject all attributes and values of the given object on every logged event, overriding any existing value. Some payloads may reject attributes they do not support.coveoua('set', 'custom', <OBJECT>)
: Attempts to inject all attributes and values of the given object in the custom section of an object, overriding any existing value. Use this call to pass customer specific parameters on the payload.coveoua('onLoad', <CALLBACK>)
: Calls the specified function immediately, library initialization is not required.coveoua('reset')
: Resets the state of the logger to the state before initialization.coveoua('send', <EVENT_NAME>, <EVENT_PAYLOAD>)
: Sends an event with a given name and payload to the analytics endpoint.coveoua('provide', <PLUGIN_NAME>, <PLUGINCLASS>)
: Registers a given pluginClass with the analytics library under the provided name.coveoua('require', <PLUGIN_NAME>)
: Explicitly loads the plugin with the given name.coveoua('callPlugin', <PLUGIN_NAME>, <FUNCTION>, <PARAMS>)
: Executes the specified function with given arguments on the given plugin name. Can be shorthanded using a plugin action prefix coveoua(<PLUGINNAME>:<FUNCTION>, <PARAMS>)
.Coveoua is set up in a modular way with different plugins providing functionality that may be specific to a given usecase. This allows you to customize some of its behavior dynamically. By default, the following plugins are loaded at library initialization:
ec
: eCommerce plugin which takes care of sending eCommerce specific events.svc
: Service plugin which takes care of sending customer service specific events.Plugin actions extend the set of available actions. They can be executed either via the callPlugin
action above, or via the shorthand. For example, to call the function addImpression
on the ec
plugin, you'd specify coveoua('ec:addImpression', ...)
.
It is possible to disable loading of any plugins by explicitly initializing the library with an empty list of plugins using coveoua('init', <API_KEY>, {plugins:[]})
.
In most common integration usecases, you will be using Coveo pre-wired components (e.g. jsui, headless or atomic) to handle communication with the Coveo backend. These components have their own specific apis to handle event logging.
When you are not using any specific Coveo web component, you need to send these events payloads explicitly, use the send
action to transmit an assembled payload to the usage analytics backend. See the Usage Analytics Events documentation for description of the payload contents. The following event types are supported in coveoua:
search
: sends a client side search event.click
: sends a click event.view
: sends a view event.custom
: sends a custom event.collect
: sends a collect event payload. We strongly recommend you use the simplified api in the ecommerce plugin to send these events instead.For example, in order to send a click event after a user has interacted with a Coveo provided result, first initialize the library with an api key and then send a click event with the appropriate payload. Refer to the click event documentation for up to date information on event payloads.
1coveoua('send', 'click', {...});
You should be able to observe the click event being transmitted to the Coveo backend at https://analytics.cloud.coveo.com/rest/ua/click
in the Developer tool's Network tab of your browser of choice.
Commerce specific events such as product selections, shopping cart modifications and transactions are sent to Coveo in the compact collect protocol. Rather than explicitly assembling these payloads by hand, the eCommerce plugin provides APIs to assemble and transmit the payloads. The event
is specific to the eCommerce plugin:
event
: An event, which has been assembled through different plugin actions.The eCommerce plugin supports adding product data (ec:addProduct
) as well as setting the appropriate event action through ec:setAction
. These calls can be used in series to assemble different types of payloads:
As a sample, here is how a cart modification event is assembled:
ec:addProduct
action to include the relevant product data in the event you’re about to send
1coveoua('ec:addProduct', <PRODUCT_DATA>);
ec:setAction
action to specify that the action done on this data is an addition to the cart.
1coveoua('ec:setAction', 'add');
send
action to send the generic event to Coveo Usage Analytics. The payload is implicit in this case, and has been generated by the plugin.
1coveoua('send', 'event');
To help track a visitor across different domains, the library offers functionality to initialize a clientId from a URL query parameter. The query parameter is named cvo_cid
with value <clientid>.<timestamp>
. The clientId is encoded without dashes and the timestamp is encoded in seconds since epoch, both to save space in the url. Both are separated by a period. A sample parameter could be cvo_cid=c0b48880743e484f8044d7c37910c55b.1676298678
. This query parameter will be picked up by the target page if the following conditions hold:
cvo_cid
query parametercoveoua('link:acceptFrom', [<referrers>])
.Given that you want to ensure the clientId remains consistent when you navigate from a source page on http://foo.com/index.html to a target page http://bar.com/index.html, the following steps are needed.
href
is replaced by coveoua('link:decorate', 'http://bar.com/index.html')
. For example, by creating an onClick event listener on the element or on the page. It's important that the decorated link is generated at the moment the link is clicked, as it will be valid only for a short time after generation.1<script> 2 async function decorate(element) { 3 element.href = await coveoua('link:decorate', element.href); 4 } 5</script> 6<a onclick="decorate(this)" href="http://bar.com/index.html">Navigate</a>>
coveoua('link:acceptFrom', ['foo.com']);
immediately after script load.Information for contributors or Coveo developers developing or integrating coveoua.
1git clone 2npm install 3npm run build
There are two ways to run your code locally:
Run npm run start
and open your browser on http://localhost:9001
Debugging through VSCode debugger with the Debug: Start Debugging
command, using the Launch Chrome
configuration.
To test out your changes, add coveoua
function calls in the public/index.html
file and check the payload in the Developer Console
section of your browser.
npm run test
.Debug: Start Debugging
command, using the Jest All
configuration.Coveo.analytics.js tracks interactions from the same browser client, through a client side provided uuid called a clientId
. This clientId is initialized on first use and there are multiple options for persisting it's value:
By default, coveoua will use both local storage and cookie storage to persist its clientId. If your environment does not support local persistence, it's possible to write your own storage abstraction.
Since React Native does not run inside a browser, it cannot use cookies or the local/session storage that modern browsers provide. You must provide your own Storage implementation. Thankfully, there exist multiple packages to store data:
A sample React native storage class implementation could look as follows
1import {CoveoAnalyticsClient, ReactNativeRuntime} from 'coveo.analytics/react-native';
2// Use any React native storage library or implement your own.
3import AsyncStorage from '@react-native-async-storage/async-storage';
4
5// Sample storage class
6class ReactNativeStorage implements WebStorage {
7 async getItem(key: string) {
8 return AsyncStorage.getItem(key);
9 }
10 async setItem(key: string, data: string) {
11 return AsyncStorage.setItem(key, data);
12 }
13 async removeItem(key: string) {
14 AsyncStorage.removeItem(key);
15 }
16}
17
18// Create an API client with a specific runtime
19const client = new CoveoAnalyticsClient({
20 token: 'YOUR_API_KEY',
21 runtimeEnvironment: new ReactNativeRuntime({
22 token: 'YOUR_API_KEY',
23 storage: new ReactNativeStorage(),
24 }),
25});
26
27// Send your event
28client.sendCustomEvent({
29 eventType: 'dog',
30 eventValue: 'Hello! Yes! This is Dog!',
31 language: 'en',
32});
Chrome, Firefox, Safari, Edge. IE11 support on a reasonable-effort basis.
See CONTRIBUTING.md
MIT license (see LICENSE).
No vulnerabilities found.
Reason
20 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
Found 9/23 approved changesets -- score normalized to 3
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
11 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More