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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745627280a4636885.html
评论列表(0条)