Skip to content

Commit

Permalink
Fix umami-software#191 - improve node-client example
Browse files Browse the repository at this point in the history
  • Loading branch information
boly38 committed Oct 16, 2024
1 parent c6f1000 commit 9274574
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/content/docs/api/node-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,51 @@ 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](https://www.npmjs.com/package/@umami/node).

Source of this package is located in [umami-software/node](https://github.com/umami-software/node) GitHub repository.

## Usage

```js
import umami from '@umami/node';

umami.init({
//~ 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
hostUrl: 'https://umami.mywebsite.com' // URL to your Umami instance
// ,userAgent // (optional) agent specifications ( OS / Browser / Device )
});

umami.track({ url: '/home' });
//~ (optional) identify : update with you own session attributes
const sessionId = Date.now();
const identifyOptions = {
"attribute": "11.23",
"sessionId": sessionId
}
umamiClient.identify(identifyOptions);

//~ track a page
const url = `https://myapp.example.com/home`;
const title = "title of /home";
umamiClient.track({url, title});

//~ track an event - an event has a *name*
umamiClient.track({url, title, "name": "button-click"}, {"color": "red"});
```

If using Umami Cloud, you can use `https://cloud.umami.is` as the host URL.
If you're using Umami Cloud, then you can use `https://cloud.umami.is` as `hostUrl`.

The properties you can send using the `.track` function are:
As `.track` function first 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
- **name**: Event name (for custom events)
- **data**: Event data properties
And to track event:
- add **name**: Event name

As `.track` function second argument, you can add custom event information :
- **data**: Event data custom properties

0 comments on commit 9274574

Please sign in to comment.