Analytics

Logins, signups, clicks and live users for your own apps.

See who is using what you shipped, without a second tool. Add the SDK, then read live users, signups and revenue in the dashboard.

npm install @vantrex/analytics

Create an analytics project in the dashboard (New project, then Analytics project) to get two keys:

Key Looks like Where it may be used
Publishable vtxa_pk_… Browser or server. It can only report page activity and clicks.
Secret vtxa_sk_… Server only. Reports logins, sign-ups and who a visitor is. Never ship it to a browser.
NEXT_PUBLIC_VANTREX_ANALYTICS_KEY=vtxa_pk_…
VANTREX_ANALYTICS_SECRET=vtxa_sk_…

In the browser

Next.js:

// app/layout.tsx
import { VantrexAnalytics } from "@vantrex/analytics/next";

export default function Layout({ children }) {
  return (
    <html>
      <body>
        {children}
        <VantrexAnalytics />
      </body>
    </html>
  );
}

Any other framework:

import { init, track } from "@vantrex/analytics/client";

init({ publishableKey: "vtxa_pk_…" });
track("checkout_clicked", { plan: "pro" });

Elements with data-vtx-track="name" are counted when clicked. The browser sends a small heartbeat every 20 seconds while the tab is visible; that is what the Active users page shows.

On your server

// lib/analytics.ts
import { createAnalytics } from "@vantrex/analytics/server";
export const analytics = createAnalytics(); // reads VANTREX_ANALYTICS_SECRET

// after a successful sign-in
await analytics.trackLogin({ userId: user.id, email: user.email, request });

// a failed one
await analytics.trackLogin({ userId: "", ok: false, errorCode: "bad_password", request });

Pass the incoming request so Vantrex gets the visitor’s country and browser, and the id that links them to their tab. Calls never throw into your code.

Dashboards

Arrange stat, chart, map and revenue panels the way you read them. Values and currency for revenue can only come from your server key.