Skip to content

Quickstart ​

Install Vectelle on a live site in three steps: paste the loader snippet, track your first event, and check that it arrived.

Before you start ​

You need two things from your Vectelle account:

  • A site key, starting with pk_live_. It's public: it's safe to put in your page's HTML.
  • Your site's origins on the key's allowlist. The site key only works from the origins listed for it, such as https://www.example.com. List every origin that will send events, including www and non-www variants and any staging domains. Requests from any other origin are refused.

1. Add the loader snippet ​

Paste this into the <head> of every page, and replace pk_live_REPLACE_ME with your site key:

html
<script>
  !((w,d,u)=> {if(w.vectelle)return;var q=[],v=w.vectelle={q:q};
  ['init','track','page','identify','reset','register','unregister','consent','debug','flush','use']
  .forEach((m)=> {v[m]=function(){q.push([m,[].slice.call(arguments)])}});
  var s=d.createElement('script');s.async=1;s.src=u;d.head.appendChild(s)})
  (window,document,'https://CDN_HOST/vectelle.js');

  vectelle.init('pk_live_REPLACE_ME', { endpoint: 'https://INGEST_HOST/v1/batch' });
</script>

The snippet defines window.vectelle straight away and loads the SDK asynchronously, so it never blocks your page. Anything you call before the SDK finishes loading is queued and replayed in order.

Page views

To record a page_view on every page load, and on route changes in single-page apps, pass autoPageviews: true:

js
vectelle.init('pk_live_REPLACE_ME', { endpoint: 'https://INGEST_HOST/v1/batch', autoPageviews: true })

2. Track an event ​

Call vectelle.track() wherever something worth recording happens:

js
vectelle.track('item_viewed', { item_id: 'vid_88', item_type: 'video' })

Event names are lower_snake_case. Properties are any JSON object. See Tracking events for naming rules and limits, and Recommended events for standard names and shapes.

When a user logs in, link their events to your own user id:

js
vectelle.identify(user.id) // on login
vectelle.reset() // on logout

3. Check that it works ​

Turn on debug logging in the browser console on your site:

js
vectelle.debug()

Then trigger an event. You should see [vectelle] track item_viewed and, within about 5 seconds, [vectelle] sent 1 event(s). In the Network tab there's a POST to /v1/batch that returned 202.

If you see tracking disabled or a 401 or 403, see Troubleshooting.

Next steps ​