https://github.com/NodeBB/nodebb-widget-essentials/blob/master/library.js#L80-L113
Should give you some ideas, the active users widget changes behaviour based on where it is displayed, if its inside a topic it shows the poster in that topic, if its inside a category it shows recent posters in that category etc. widget.area.url gives the url of the page the widget is in.