Plain HTML / Django templates
Add analytics to any server-rendered project — Django, Rails, Laravel, static sites — with a single script tag. No npm, no bundler, no build step required.
1. Add the script tag
Paste this inside <head> or just before </body> in your base template. Replace proj_xxxx and pk_xxxx with your project ID and API key from the dashboard.
<!-- base.html / base template --><scriptsrc="https://cdn.jsdelivr.net/npm/nohmo@latest/dist/n.min.js"data-project="proj_xxxx"data-api-key="pk_xxxx"defer></script>
Note: The defer attribute makes the script load without blocking the page render and ensures window.nohmo is ready before any inline scripts run after the page loads.
2. That's it — auto-tracking is on
As soon as the script loads, the following are tracked automatically with no extra code:
| Event | Trigger |
|---|---|
| PAGE_VIEW | On every page load |
| TIME_SPENT | When the tab is hidden or the page is closed |
| SCROLL_DEPTH | At 25%, 50%, 75%, 100% scroll milestones |
| CLICK | Any click on a link, button, input, or form element |
| RAGE_CLICK | Three or more rapid clicks in the same spot |
3. Track custom events
Use window.nohmo.send() from any inline script or event handler.
<!-- inline event handler --><button onclick="window.nohmo.send('signup_clicked', { plan: 'pro' })">Sign up</button><!-- or from a <script> block --><script>document.getElementById('buy-btn').addEventListener('click', function () {window.nohmo.send('purchase_started', { productId: '{{ product.id }}', price: {{ product.price }} })})</script>
4. Identify users (Django example)
After the user logs in, call window.nohmo.identify() to link the device to a real user. All anonymous events fired before login are retroactively attached to that user.
{% if user.is_authenticated %}<script>window.nohmo.identify('{{ user.pk }}', '{{ user.email }}')</script>{% endif %}
Note: identify() takes a user ID as the first argument and an optional email as the second. You can also pass a third argument — any JSON object — as extra metadata stored on the user profile.
API reference
| Method | Arguments | Description |
|---|---|---|
| window.nohmo.send(event, data?) | event: string, data?: object | Track a custom event with optional data payload |
| window.nohmo.identify(userId, email?, meta?) | userId: string, email?: string, meta?: object | Link this device to a real user identity |
CDN URL
The script is served from jsDelivr, which mirrors every npm package automatically. The URL always resolves to the latest stable release:
https://cdn.jsdelivr.net/npm/nohmo@latest/dist/n.min.js
To pin to a specific version (recommended for production), replace @latest with a version number, e.g. @0.3.11.