The Umami node client allows you to send data to Umami on the server side.
npm install @umami/node
This command will install api client npm package.
import umami from '@umami/node';
//~ init
let umamiClient = new umami.Umami({
websiteId: '50429a93-8479-4073-be80-d5d29c09c2ec', // Your website id
hostUrl: 'https://umami.mywebsite.com' // URL to your Umami instance
// ,userAgent // (optional) agent specifications ( OS / Browser / Device )
});
//~ (optional) identify : update with you own session attributes
const sessionId = Date.now();
const identifyOptions = {
"attribute": "11.23",
"sessionId": sessionId
}
await umamiClient.identify(identifyOptions);
//~ track a page
const url = `/home`;
const title = "title of /home";
let event = {url, title}
await umamiClient.track(event);
console.log(`✮ Page ${JSON.stringify(event)}`);
//~ track an event - an event has a *name*
const data = {"color": "red"};
event = {url, title, "name": "button-click", data};
await umamiClient.track(event);
console.log(`✮ Event ${JSON.stringify(event)}`);
If you're using Umami Cloud, then you can use https://cloud.umami.is
as hostUrl
.
As .track
function event argument, the properties you can send are:
- hostname: Hostname of server
- language: Client language (eg. en-US)
- referrer: Page referrer
- screen: Screen dimensions (eg. 1920x1080)
- title: Page title
- url: Page url
And to track event:
- name: Event name
- data: Event data custom properties