Setting session id for first visit


#1

I am logging web visits with a before_filter on the application
controller. The issue I’m having is that the initial visit does not
return a session id. I’m using the SqlSessionStore and the function
MysqlSession.find_session(session.session_id) to retrieve the session
id. If it doesn’t exist I use a -1. So looking in my visits table the
initial visit always has -1 for the session id and the rest of the
visits contain a valid session id for that visitor.

I tried putting the logging of visits in the after filter but that
didn’t seem to work. Is this something that I can correct or is that
just the way it is with sessions?

Thanks,
Gunner


#2

It makes sense that the initial visit would not have a session id
because depending on where you are assigning it, you might be logging
the variable before setting it.

Also, you don’t really need to hang on to the session details when
logging web visits. Unless you have a special reason to, i wouldn’t
track any of the session details, they can easily be crated and
compromised by scripts anyway. Try to keep session data to a minimum.

You might need to show some code if this doesn’t help.

Kent

gwgeller wrote:

I am logging web visits with a before_filter on the application
controller. The issue I’m having is that the initial visit does not
return a session id. I’m using the SqlSessionStore and the function
MysqlSession.find_session(session.session_id) to retrieve the session
id. If it doesn’t exist I use a -1. So looking in my visits table the
initial visit always has -1 for the session id and the rest of the
visits contain a valid session id for that visitor.

I tried putting the logging of visits in the after filter but that
didn’t seem to work. Is this something that I can correct or is that
just the way it is with sessions?

Thanks,
Gunner


#3

Kent,
I guess I really haven’t thought it through, but my original
purpose was to group a visit using the session id as opposed to an ip
which could potentially be the same for two visitors. You mentioned
where I set the session id, but I don’t do it, SqlSessionStore does it
for me, but I’m curious has to how that works. Do you know when the
session would be set?

On Oct 22, 10:25 am, Kent F. removed_email_address@domain.invalid


#4

At work we do something similar, although we dont have issues with the
session_id using ActiveRecordStore. One approach you could take would
be to create a new object (Visitor), and store the visitor.id in the
session. Then use the before filter to load that Visitor on each
request. Then, create an Event associated with that visitor for each
request (this allows you to have multiple event_types). Then when
doing your queries you can do visitor.events to see what each person
did. This approach allows us to clean the session table out every few
days so it doesnt get to slow. The visitor table only gets written to
once for each person and then is read only going forward.