umami-software / node

Umami Node.js library
11 stars 4 forks source link

Determining location in Node.js #3

Closed franciscop closed 3 weeks ago

franciscop commented 1 month ago

How do you make sure to pass the proper data to determine the location with Umami? Country-level would def be enough for me, I'd guess it's either with the IP or with the language region? So what kind of option can I set in Node.js for this?

mikecao commented 3 weeks ago

You don't need to pass anything. Umami will figure it our from the IP alone.

franciscop commented 3 weeks ago

Sorry, this is in Node.js, so how does Umami know the IP with this code? When using e.g. Express, wouldn't I need to pass the IP of the client somehow? I believe right now Umami is receiving+using my hosting provider's IP address instead of the client's one with this code:

import umami from '@umami/node';

umami.init({
  websiteId: '...', // Your website id
  hostUrl: '...'
});

// Where do I put either `req` or `ip`?
var ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress 

// Without passing an IP, the "IP" of this request is the hosting one, not the client's one
umami.track({ url: '/home' });
franciscop commented 3 weeks ago

Never mind, I found this to know how to pass it!

https://github.com/umami-software/umami/issues/814