Custom events

Custom events let you measure the actions that lead to revenue: signups, trial starts, add-to-carts, downloads. Events show up in your dashboard with conversion rates and attributed revenue, and can be used as funnel steps.

Declarative HTML attributes

No JavaScript needed — mark any element with a trigger attribute. The value is the event name, optionally followed by space-separated key=value metadata pairs (quote values that contain spaces):

<!-- Fires "start-trial" when clicked -->
<a href="/signup" data-revscope-click="start-trial">
  Start free trial
</a>

<!-- Same as click, but always flush via sendBeacon
(more reliable for links or events that cause navigation) -->
<button type="button" data-revscope-beacon="checkout-started">
  Checkout
</button>

<!-- Click with metadata (space-separated key=value pairs) -->
<a href="/signup" data-revscope-click="start-trial plan=growth billing=yearly">
  Start growth trial
</a>

<!-- Fires "saw-pricing" when scrolled into view -->
<section id="pricing" data-revscope-visible="saw-pricing">
  ...
</section>

Clicks on same-tab navigational links (an <a href> that would leave the page) automatically use sendBeacon, so you usually do not need data-revscope-beacon on ordinary links. Soft SPA navigations that call preventDefault are left on the normal send path.

Marked elements are re-scanned on SPA navigations, so data-revscope-visible events re-arm on each new page.

Attributes also work on elements added after the page loads — the tracker watches the document for new markup, so lazily loaded sections, client-rendered views, and modals are picked up without any extra calls.

JavaScript API

Call dispatch anywhere on the page (or the name you set in the stub's name config):

dispatch("event", "signup");

// With metadata (up to 4kb of JSON)
dispatch(
  "event",
  "signup",
  { metadata: { plan: "growth", billing: "yearly" } }
);

// With a callback, e.g. before navigating away
dispatch(
  "event",
  "checkout-started",
  {
    beacon: true, // flush immediately via sendBeacon
    callback: function () {
      window.location.href = "/checkout";
    },
  }
);

Event names are normalized to lowercase alphanumerics and dashes, and limited to 100 characters. Options:

Option Description
metadata A plain object of extra properties, serialized as JSON (max 4kb).
callback Function invoked once the event has been queued or sent. You can use this to e.g. redirect after the event has been recorded. Triggers an immediate flush.
beacon Flush the tracking queue synchronously with sendBeacon. Use for events that immediately precede a navigation, like exit links where the delay from using callback is not desired. Triggers a normal flush in Internet Explorer or older Opera browsers, which is unreliable on unload.

Calling before the script loads

The required install stub queues events fired before the tracker initializes and replays them automatically:

<script>(function(w,n,u,c){
    if(u&&typeof u==="object"){c=u;u=null}c=c||{};u=u||"https://in.revscope.co/";c.url=u;u+=n+".js";c.project=n;n=typeof c.name==="string"&&c.name||"dispatch";if(typeof w[n]==="function")return;var q=[];function f(){q.push([].slice.call(arguments));}f.q=f.a=q;f.c=c;w[n]=f;var s=document.createElement("script");s.src=u;s.defer=true;document.head.appendChild(s);
  })(window, "REPLACE_WITH_PROJECT_NAME");
</script>
Next: attach session context with custom metadata, or connect a payment provider in integrations.