openrevenue
v1.0.3
Published
Privacy-friendly web analytics tracker for OpenRevenue — init, track custom events, and attribute purchases.
Maintainers
Readme
openrevenue
Privacy-friendly web analytics for OpenRevenue.
Install
npm install openrevenueUsage (bundlers / SPA)
import { init, track, transaction, getVisitorId, isReady, onReady, version } from "openrevenue"
init({ siteId: "your-project-id" })
onReady(() => {
track("signup", { plan: "pro" })
})
transaction("checkout_completed", { amount: 29, currency: "USD" })
const visitorId = getVisitorId() // Polar / checkout attributionOptions
init({
siteId: "your-project-id",
apiHost: "https://api.openrevenue.com", // optional
allowLocalhost: false, // test only — never in production
})After init, the same API is also on window.openrevenue (script-tag compatible).
Next.js
Prefer the CDN helper so the tracker stays outside your app bundle:
import { OpenRevenueScript } from "openrevenue/next"
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<OpenRevenueScript siteId="your-project-id" />
</body>
</html>
)
}React (bundled tracker)
import { OpenRevenueProvider, useTrack } from "openrevenue/react"
export function App() {
return (
<OpenRevenueProvider siteId="your-project-id">
<CheckoutButton />
</OpenRevenueProvider>
)
}
function CheckoutButton() {
const track = useTrack()
return <button onClick={() => track("checkout_click", { plan: "pro" })}>Buy</button>
}Script tag (no npm)
<script
defer
src="https://api.openrevenue.com/tracker.js"
data-site="your-project-id"
></script>Docs
Publishing
Releases use npm Trusted Publishers (GitHub Actions OIDC → npm stage publish). Tag format: openrevenue-vX.Y.Z.
License
MIT
