We’re at capacity right now: new teams join from the waiting list. Join the waiting list →
Kolvantage

Docs › Developers

JavaScript API

Once the Kolvantage script is on your pages, your website's code can talk to it through window.Kolvantage: add tags to a visit, fire events, show a survey, open the chat, say who the visitor is, and let visitors opt out. This page lists every method, plus the HTML classes that keep parts of a page out of recordings.

The command queue

The Kolvantage script loads in the background (async), so your code may run before it is ready. Use the queue: it works whether the script has loaded yet or not.

window._shq = window._shq || [];
_shq.push(['tag', 'plan', 'pro']);
_shq.push(['event', 'purchase', { value: 49.90 }]);

Each entry is an array: the method name, then its arguments. Commands pushed before the script loads run as soon as it loads, in order. After that, _shq.push runs them right away. You can push several at once: _shq.push(['tag', 'plan', 'pro'], ['event', 'signup']).

Once the script has loaded, you can also call the methods directly, for example Kolvantage.tag('plan', 'pro'). Kolvantage.loaded is true then.

Mistakes (a wrong tag name, an unknown command) show as a warning in the browser console, starting with [Kolvantage]. Nothing breaks on your page.

Methods

MethodWhat it does
tag(name, value) or tag({ … })Attaches values to this visit and visitor
event(name, data)Fires a custom event, optionally with an amount
goal(name)The older name of event(name)
survey(id)Shows a survey now
chat(action)Opens or closes the chat box
identify(customerId)Says who the visitor is, for Marketing
visitorId(callback)Gives this visitor's Kolvantage id
push(action)Asks for web push notifications, or unsubscribes
optOut()Stops Kolvantage for this visitor, and remembers it
optIn()Undoes optOut()
stop()Stops recording on this page

tag

Attaches values to the visit, for example after login. Tags show on the recording, are searchable in Recordings and Visitors, and are remembered on the visitor's profile.

_shq.push(['tag', 'customer', 246245]);
_shq.push(['tag', { user_id: 246245, plan: 'vip', level: 'gold' }]);
  • Names: letters, numbers and _ . : -, up to 40 characters. An invalid name is ignored with a console warning.
  • Values: text, numbers or true/false, up to 200 characters. An empty value ('', null, undefined) is ignored.
  • Sending a tag again replaces its value.
  • Up to 50 tags per visit.
  • Tags are saved for every visit. On a visit that isn't recorded (if you record less than 100% of visits in Settings → Recordings → Record this share of sessions), they are kept on the visitor's profile, and the customer id tag still says who the visitor is.

If one tag is your customer id (for example user_id), name it in Settings → Tags → Customer id tag. Pages sending that tag then say who the visitor is, like identify() (see below).

#### Signed tags

A visitor can change what their browser sends, so a tag like the customer id could be faked. For a tag your team relies on, turn on Signed only in Settings → Tags. Kolvantage then keeps that tag only when your website's server signed its value; anything else for it is dropped. Signed tags show with ✓ in the dashboard.

To sign a value, your server computes HMAC-SHA256 of the value (exactly as you send it, as text) with the website's signing secret, as hex, and puts the signature in the page with the tag:

_shq.push(['tag', 'user_id', '246245', { signature: 'SIGNATURE-FROM-YOUR-SERVER' }]);
// or: Kolvantage.tag('user_id', '246245', { signature: '…' })

Several tags at once: give each signed tag its own signature (tags that aren't signed-only need none):

_shq.push(['tag',
  { user_id: '246245', email: 'dana@example.com', plan: 'vip' },
  { signatures: { user_id: 'SIGNATURE-OF-246245', email: 'SIGNATURE-OF-dana@example.com' } }]);

For example in PHP: hash_hmac('sha256', (string) $customerId, $signingSecret). In Node.js: crypto.createHmac('sha256', signingSecret).update(String(customerId)).digest('hex'). Never put the signing secret in the page or in JavaScript: only your server may know it. Settings → Tags has a step-by-step guide for your developer, with ready-to-copy code for PHP, Node.js and Python (Flask and Django), for one tag or several.

Campaign parameters in the landing page address (utm_source, utm_medium, utm_campaign, utm_term, utm_content, utm_id, gclid, gbraid, wbraid, gad_source, gad_campaignid, dclid, fbclid, msclkid, ttclid, twclid, li_fat_id, epik, sccid) become tags on their own.

event

Fires a custom event that you defined in the website's Events tab, set to come from Website code (browser).

_shq.push(['event', 'signup']);
_shq.push(['event', 'purchase', { value: 49.90 }]);
_shq.push(['event', 'purchase', { value: 49.90, currency: 'EUR' }]);
  • name: the event's code name, as shown in the Events tab (letters, numbers and _ . : -, up to 40 characters).
  • value (optional): the amount, for events with an amount. A number works best; text like "$1,299.50" is understood too. It is rounded to 2 decimals.
  • currency (optional): overrides the event's currency. Supported: USD, EUR, GBP, ILS, CAD, AUD, JPY, CHF, SEK, NOK, DKK, PLN, BRL, MXN, INR, ZAR.

How it behaves:

  • Events fire on every visit, recorded or not. They are not sent while recording is paused, from excluded IP addresses, from pages outside the website's domain, for visitors who opted out, or (when Respect "Do Not Track" is on) for visitors whose browser asks not to be tracked.
  • Events fired before the script is ready wait (up to 50) and are sent once it is. If the visit turns out not to be tracked (see above, or the hub can't be reached), a console warning says why they weren't sent.
  • Events that aren't defined in the Events tab are ignored, unless an A/B test uses them as a goal.
  • Events set to Your server (API) are refused from the browser. Send them with the server API.
  • Events count as A/B test goals for the tests the visitor is in, and the visit gets an event:NAME tag.

goal('name') from older setups still works: it fires the event without an amount.

See Events.

survey

Shows a survey right away. Use it for surveys whose trigger is Manual, for example from a "Give feedback" button.

_shq.push(['survey', 'SURVEY-ID']);
  • The survey must be active.
  • It doesn't show again to a visitor who already finished or closed it (following the survey's frequency setting).
  • When you call it this way, the survey's device, percentage and page rules don't apply.
  • If called before the script is ready, the survey shows as soon as it is. If the visit isn't tracked (for example the visitor opted out, or recording is paused), a console warning says why it didn't show.

The survey id is in the survey's page in the dashboard. See Surveys.

chat

Opens or closes the live chat box, for example from a "Chat with us" link.

Kolvantage.chat('open');
Kolvantage.chat('close');

This works only where the chat box is on the page: the live chat is on for the website, the box shows on this device, and it has loaded. Otherwise you get a console warning. See Live chat.

identify

Says who the visitor is, with your own id for them (for example after login). Their Marketing user then includes this browser, with its visits, events and web push subscription.

_shq.push(['identify', 'CUSTOMER-ID']);
  • The id can be up to 128 characters.
  • It sends only the id: no email or phone. Send those from your server with the users API.
  • It works only while Allow identify from the website's pages is on in Settings → API. Turn it off if only your server should say who a visitor is: anyone could otherwise call identify with another customer's id in their own browser. If you sign your customer id tag (Settings → Tags), identify from a page is refused: send the customer id as a signed tag instead.

See Marketing.

visitorId

Gives this visitor's Kolvantage id. Your server needs it to link server events and users to the visitor.

var id = Kolvantage.visitorId();
// or, before the script may have loaded:
_shq.push(['visitorId', function (id) { /* send it to your server */ }]);

The same id is in the kv_vid cookie on your own domain (and its subdomains), so your server can usually read it from the customer's requests without any extra code.

For a visitor who opted out, visitorId() gives only an id their browser already had (or null), and sets no cookie.

push

Controls web push, where it is turned on (Settings → Marketing → Web push).

Kolvantage.push('prompt');       // ask the visitor to allow notifications
Kolvantage.push('unsubscribe');  // stop notifications for this browser
  • prompt shows the small box first (then the browser's question), even if the visitor clicked Later before. If they already allowed notifications, it just subscribes them.
  • Use prompt from your own button when How to ask visitors is set to Don't ask (only when your code calls Kolvantage.push("prompt")).
  • If web push is off for the website, or hasn't loaded yet, you get a console warning.

See Marketing channels.

optOut and optIn

Lets visitors say no to Kolvantage, for example from your cookie banner.

Kolvantage.optOut();
Kolvantage.optIn();
  • optOut() stops recording on the current page and remembers the choice in this browser. On later pages, Kolvantage records and counts nothing for this visitor: no recording, heatmaps, surveys, events, A/B tests (they see the original page), web push prompt or kv_vid cookie, and they don't show in Live. The live chat box still shows, if the chat is on.
  • optIn() removes the choice. Kolvantage starts again from the next page load.
  • The choice is kept in the browser's storage, so it applies per browser and device. Clearing site data removes it.

See Privacy for what opt-out does and doesn't cover.

stop

Stops recording, heatmap data, form analytics and surveys on the current page only. The next page starts again as usual.

Kolvantage.stop();

HTML classes for privacy

Add these classes to your page's HTML to control what recordings show.

ClassWhat it does
mh-blockThe element is not recorded at all. It replays as an empty box of the same size
mh-maskThe text inside the element replays as *
mh-ignoreTyping into this input is not recorded. Form analytics also skip it
<div class="mh-block">Account balance: $1,200</div>
<span class="mh-mask">Dana Cohen</span>
<input name="coupon" class="mh-ignore">

Heatmaps don't use the text of links and buttons inside these elements as labels.

Password fields are always masked, and fields of type email and tel are masked by default, and so are fields that hold private details: cards, addresses, birth dates, one-time codes and names (found by the field's autocomplete value, name, id or placeholder). Settings → Recordings → Hide everything visitors type masks every field. See Privacy.

The script tag

The website id is part of the script address: hub.js?site=WEBSITE-ID. A data-site="WEBSITE-ID" attribute on the script tag works too, but tag managers remove it, so the address form is the one to use. Having the script twice on a page does no harm: it runs once.

See Install for the recommended snippet.

Google Tag Manager and dataLayer

Kolvantage doesn't read or write the dataLayer. To install it through Google Tag Manager, paste the script line into a Custom HTML tag with the All Pages trigger (see Install).

To send something from GTM to Kolvantage, use another Custom HTML tag that pushes to the queue, fired by your GTM trigger:

<script>
  window._shq = window._shq || [];
  _shq.push(['event', 'signup']);
</script>

Previewing an A/B test variation

Add ?sh_ab=TEST-ID:VARIATION-ID to a page address to see a variation without being counted in the test. See A/B tests.

Limits

  • Tag and event names: letters, numbers and _ . : -, up to 40 characters.
  • Tag values: up to 200 characters. Up to 50 tags per visit.
  • identify ids: up to 128 characters.
  • Events queued before the script is ready: up to 50 per page.
  • One page is recorded for at most one hour. After that, the visitor stays in Live, and surveys and the chat keep working.