Microlens logo Microlens

Track button clicks and actions

See how many people sign up, download or buy, not just how many visit.

Add one attribute

Add data-microlens-event to any button or link. Every click is counted under that name in the Events card on your dashboard.

HTML
<button data-microlens-event="signup">Sign up</button>

That's it. It works with plain HTML, Webflow, Framer, React, Next.js (including Server Components), Vue and anything else that outputs HTML.

Track more than one thing

Give each element its own name. Using the same name in several places adds the clicks together.

HTML
<button data-microlens-event="signup">Sign up</button>
<a href="/app.dmg" data-microlens-event="download">Download</a>

Only count it when it succeeds

A click on "Sign up" doesn't always mean someone signed up. To count only real signups, call track from your own code instead, for example after a form submits without errors.

JavaScript
const res = await createAccount(form);
if (res.ok) window.microlens?.track("signup");

This also works for things that aren't clicks, like a video finishing or a payment going through.

Using React or Next.js?

The attribute works as is, including in Server Components. To use track in React, call it from onClick:

JSX
<button onClick={() => window.microlens?.track("signup")}>Sign up</button>

The ?. skips the call if the Microlens script hasn't loaded yet, for example during server rendering.

In Next.js, Server Components can't use onClick. Put the button in a "use client" component, or use the attribute instead.

Using TypeScript? Declare it once:

TypeScript
declare global {
  interface Window {
    microlens?: { track: (name: string) => void };
  }
}
Good to know
  • Use short, lowercase names like signup or download. Signup and signup are different events.
  • Each event counts toward your monthly event limit, the same as a pageview.
  • Events on pages you've excluded aren't counted.
  • Names can be up to 100 characters. pageview is reserved.