javascript - meteor app: how to get a unique sessionclient id without using accounts - Stack Overflow

In my meteor app, I need to be able to capture some form of unique element (session idclient id, etc..

In my meteor app, I need to be able to capture some form of unique element (session id/client id, etc...) to help keep track of the actions that user makes. At this point, I'm not using accounts package, so I'm just looking for a way to capture some sort of client-unique data element, which I could use in the data model to track activities/steps of every unique user. What application / browser / session element could I use in place of this unique id string?

In my meteor app, I need to be able to capture some form of unique element (session id/client id, etc...) to help keep track of the actions that user makes. At this point, I'm not using accounts package, so I'm just looking for a way to capture some sort of client-unique data element, which I could use in the data model to track activities/steps of every unique user. What application / browser / session element could I use in place of this unique id string?

Share Improve this question asked Apr 8, 2014 at 13:41 Eugene GoldbergEugene Goldberg 15.6k23 gold badges98 silver badges179 bronze badges 1
  • You should take a look at answers from that question – Remi Commented Apr 8, 2014 at 13:57
Add a ment  | 

3 Answers 3

Reset to default 6

This what you are looking for?

You can just use Random.id() to get a unique id string. I have used this a number of times to track temporary objects and it is super helpful. There are other Random methods too that may e in handy.

What you can try to use is DDP connection's session ID Meteor.connection._lastSessionId. But be careful, because it is basically websocket session. So when the client open a new tab or refresh the page, this sessionId will be different .

If you want to keep the same session in the browser you can try to implement your own localStorage based session.

Some thoughts: Instead of using Meteor's Random.id(), insert a new doc into a Mongo collection, this way you are guaranteed there will be no collisions. As there is always a tiny chance that Random.id() will return a duplicate. Is that a correct assumption?

Meteor docs say likely to be unique, i.e. Not guaranteed to be unique. http://docs.meteor./#/full/random

Store the _id of the doc in a Session.set() call, to use as your anonymous userId, i.e. Session.get("anonUserId") When done you can delete it to keep the collection trim.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745627280a4636885.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信