How to set/get a global session variable?


#1

Matrix Version: 5.4

Hi there,

So, I need to write a piece of code which fires whenever a “new user session” starts. i.e. only on the first entry page, not on any subsequent pages during that session.

I think this may work %globals_session_xxxxxxxx%

But in the manuals it says it only work with Triggers …! Is there any trigger-less solution ?

Also had a look at this option but not sure how to implement it in Matrix …

Thanks


(Marcus Fong) #2

Hi, Paul - is there a reason you don’t want to use triggers? Performing an action when a certain event occurs is exactly what Matrix triggers are intended for.

In this case, it sounds like you’d want to set up a trigger to fire on the User Login event: https://matrix.squiz.net/manuals/triggers/chapters/trigger-events#User-Login


#3

Hi Marcus, Thanks for your reply.

No, there is no login involved here necessarily…

I just want to create/start a session whenever ANY user (logged in or not logged in) comes to our website.

So in a sense, if he is NOT logged in, I want to assign him a unique value and store that value in a session, so that I can track his activity. Sort of like how GA works … Now sure if this is achievable from within Matrix ???

Thanks


(Marcus Fong) #4

Oh, I see what you mean. How about the Public User Session Created trigger event, then?

https://matrix.squiz.net/manuals/triggers/chapters/trigger-events#Public-User-Session-Created


#5

Great, looks promising … I will test and report back …

Thanks again Marcus