Skip to content

Commit 9274574

Browse files
committed
Fix #191 - improve node-client example
1 parent c6f1000 commit 9274574

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

src/content/docs/api/node-client.mdx

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,51 @@ The Umami node client allows you to send data to Umami on the server side.
1212
npm install @umami/node
1313
```
1414

15+
This command will install api client [npm package](https://www.npmjs.com/package/@umami/node).
16+
17+
Source of this package is located in [umami-software/node](https://github.com/umami-software/node) GitHub repository.
18+
1519
## Usage
1620

1721
```js
1822
import umami from '@umami/node';
1923

20-
umami.init({
24+
//~ init
25+
let umamiClient = new umami.Umami({
2126
websiteId: '50429a93-8479-4073-be80-d5d29c09c2ec', // Your website id
22-
hostUrl: 'https://umami.mywebsite.com', // URL to your Umami instance
27+
hostUrl: 'https://umami.mywebsite.com' // URL to your Umami instance
28+
// ,userAgent // (optional) agent specifications ( OS / Browser / Device )
2329
});
2430

25-
umami.track({ url: '/home' });
31+
//~ (optional) identify : update with you own session attributes
32+
const sessionId = Date.now();
33+
const identifyOptions = {
34+
"attribute": "11.23",
35+
"sessionId": sessionId
36+
}
37+
umamiClient.identify(identifyOptions);
38+
39+
//~ track a page
40+
const url = `https://myapp.example.com/home`;
41+
const title = "title of /home";
42+
umamiClient.track({url, title});
43+
44+
//~ track an event - an event has a *name*
45+
umamiClient.track({url, title, "name": "button-click"}, {"color": "red"});
2646
```
2747

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

30-
The properties you can send using the `.track` function are:
50+
As `.track` function first argument, the properties you can send are:
3151

3252
- **hostname**: Hostname of server
3353
- **language**: Client language (eg. en-US)
3454
- **referrer**: Page referrer
3555
- **screen**: Screen dimensions (eg. 1920x1080)
3656
- **title**: Page title
3757
- **url**: Page url
38-
- **name**: Event name (for custom events)
39-
- **data**: Event data properties
58+
And to track event:
59+
- add **name**: Event name
60+
61+
As `.track` function second argument, you can add custom event information :
62+
- **data**: Event data custom properties

0 commit comments

Comments
 (0)