The coview() JavaScript API
Every coview() command for your pages: open the chat, identify and reset users, track events, page views, listeners and consent, plus the HTML attributes.
Once the snippet is on a page, window.coview takes commands. Add the one-line queue before the snippet so your calls work even before coview has loaded:
<script>
window.coview = window.coview || function () { (coview.q = coview.q || []).push(arguments); };
</script>
Calls made early wait in the queue and run in order once coview starts. An unknown command logs a [coview] warning in the browser console.
Commands
| Command | Does |
|---|---|
coview('open') | Opens the chat panel. |
coview('close') | Closes it. |
coview('toggle') | Opens it when closed, closes it when open. |
coview('identify', {…}) | Says who is signed in. See Identify signed-in users. |
coview('reset') | On sign-out: starts a new anonymous visitor and forgets the previous one in this browser. |
coview('track', name, props) | Records one of your own events. |
coview('page', props) | Records a page view now. |
coview('on', event, fn) | Listens to an event. coview('off', event, fn) stops. |
coview('consent', { analytics }) | Passes on the visitor's analytics choice. |
Track your own events
coview('track', 'Added to cart', { sku: 'CANDLE-12', price: 24 });
- The name is stored in lowercase with underscores, accents folded: "Added to cart" becomes
added_to_cart. Names coview uses itself, such aspage_vieworclick, are reserved. - Properties: an object of up to 4 KB as JSON, up to 25 keys per level, nested up to 3 levels, text values up to 500 characters.
- Your events show as markers on the session timeline, and in Live now's event stream. An anonymous visitor's events wait in their browser and reach coview when the visitor identifies.
Or name a click in your HTML, without code: a click on an element with data-coview-track records that event instead of a plain click, and its data-coview-prop-* attributes become the properties.
<button data-coview-track="Started trial" data-coview-prop-plan="growth">Start trial</button>
Page views
coview records a page view on every page load and, with Single-page navigation on (the default), on each history.pushState, replaceState and back or forward navigation. If you turn that off, or your app changes pages another way, call coview('page') after each route change. An optional object adds properties to the page view.
Listen to events
coview('on', 'message', (m) => {
console.log('Support wrote:', m.body);
});
| Event | When |
|---|---|
ready | coview has started on the page. A listener added later is called at once. |
open, close | The chat panel opened or closed. |
message | A message from your team reached the visitor. It carries the message, with body, sender_type and sender_name. |
reset | A reset finished and the new anonymous visitor is ready. |
Consent
coview('consent', { analytics: false }); // stop recording and tracking
coview('consent', { analytics: true }); // allow them again
The browser remembers the choice. See Privacy, masking and retention.
HTML attributes
| Attribute | Effect |
|---|---|
data-coview-key | On the snippet's script tag: the site's public key. |
data-coview-open | A click on the element opens the chat. |
data-coview-track, data-coview-prop-* | A click records this event with these properties. |
data-coview-mask | Text and values inside are masked in recordings and never captured in events. |
data-coview-block (or class coview-block) | The element shows as an empty box in recordings. |
data-coview-noclick | Agents can never click it while co-browsing. |
What coview captures on its own
In Settings › Install & widget › Tracking, per site, each of these can be switched off: Single-page navigation, Clicks (links, buttons and elements with the tracking attribute), Form submits (the form's id, name and action, never field values), Scroll depth (25, 50, 75 and 90%), Time on page (30 seconds, 1 minute and 3 minutes of visible time), Outbound links, Rage clicks and Exit intent (desktop only). Page views and sessions are always on. Text typed into fields is never read.
A person from coview will help — send us a message, or book a demo and we'll walk through it with you.