admin管理员组文章数量:1435859
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
3 Answers
Reset to default 6This 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.
本文标签: javascriptmeteor app how to get a unique sessionclient id without using accountsStack Overflow
版权声明:本文标题:javascript - meteor app: how to get a unique sessionclient id without using accounts - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745627279a2667050.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论