@kryptonhq/analytics
v0.1.9
Published
Krypton Analytics JavaScript SDK — privacy-first analytics tracking
Downloads
1,048
Readme
@kryptonhq/analytics
Krypton Analytics JavaScript SDK — privacy-first analytics tracking.
Install (CDN, script tag)
<script defer src="https://cdn.jsdelivr.net/npm/@kryptonhq/analytics@latest/dist/browser.global.js"></script>
<script>
window.addEventListener("load", function () {
window.krypton = window.KryptonAnalytics.init({
apiKey: "kapi_xxx",
endpoint: "https://ingest.yourdomain.com",
autoPageview: true,
heatmap: true,
consentRequired: true,
showConsentBanner: true
})
})
</script>The CDN build exposes a global: window.KryptonAnalytics.
Install (npm)
npm install @kryptonhq/analyticsimport { createKrypton } from "@kryptonhq/analytics";
const krypton = createKrypton({
apiKey: "kapi_xxx",
endpoint: "https://ingest.yourdomain.com",
autoPageview: true,
heatmap: true,
consentRequired: true,
showConsentBanner: true,
});
krypton.track("signup", { plan: "pro" });Consent (default deny + categories)
The SDK supports category-level consent:
analytics— pageviews and custom eventsheatmaps— click and scroll interaction maps
When consentRequired: true and showConsentBanner: true, a built-in consent popup is shown automatically. No data is collected until the user grants consent.
Geolocation is resolved server-side from the request IP (no browser Geolocation API needed).
Manual consent control
krypton.setConsent({ analytics: true, heatmaps: false });
krypton.grantConsent(); // grant all
krypton.revokeConsent(); // revoke all
krypton.showConsentBanner(); // re-show the popupAPI
krypton.track("event_name", { key: "value" });
krypton.trackPageview();
krypton.identify("user-123");
krypton.flush();
krypton.shutdown();
krypton.getConsent(); // { analytics: boolean, heatmaps: boolean }