Skip to content

Commit 50fec7f

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

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,56 @@ 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+
//~ 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+
const trackPage = {url, title}
43+
umamiClient.track(trackPage);
44+
console.log(`✮ Page ${JSON.stringify(trackPage)}`);
45+
46+
//~ track an event - an event has a *name*
47+
const trackEvent = {url, title, "name": "button-click"};
48+
const eventData = {"color": "red"};
49+
umamiClient.track(trackEvent, eventData);
50+
console.log(`✮ Event ${JSON.stringify({trackEvent, eventData})}`);
2651
```
2752

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

30-
The properties you can send using the `.track` function are:
55+
The properties you can send using as `.track` function first argument are:
3156

3257
- **hostname**: Hostname of server
3358
- **language**: Client language (eg. en-US)
3459
- **referrer**: Page referrer
3560
- **screen**: Screen dimensions (eg. 1920x1080)
3661
- **title**: Page title
3762
- **url**: Page url
38-
- **name**: Event name (for custom events)
39-
- **data**: Event data properties
63+
And to track event:
64+
- add **name**: Event name
65+
66+
You can add custom event information as `.track` function second argument :
67+
- **eventData**: Event data custom properties

0 commit comments

Comments
 (0)