I’m trying to get the unique ID for an anonymous visitor to my site. I notice that when logging user.id (when user.role is ‘Visitor’) I get what appears to be a session ID, e.g.: “868660d0270775151c1dc5762405fb47738ccd4665506a510d1bcd373e366592e00bed1c62d6f8a1aecdf22e8765cdae1e60994d53964e647acf431e4f798bcdc605d9d6bee9af7d4875dfd2c4f47082a4e67ecf1c4deb74e8f176460a467929”
When checking the cookies, I see this is the value of svSession, while it seems there is an _hp2_id cookie that has a userId attribute within it.
Which is the true user ID for anonymous visitors? Is it the session, the userId cookie, or is there a 3rd place that has a GUID similar to registered user ID?
Hi Itamar!
It seems like the ID you provided is the session ID and it changes every time you close and re-open the browser. If the user just refreshes the page, the ID remains the same.
Hope it helps!
Doron.
Hi Itamar, have you been able to find out? I am also looking to find out what is the unique session ID an where to find it…
You can create your own using a NPM Package called UUID that generates random UUDIs.
Just install the NPM Package and import it.
import { session } from "wix-storage"
import { v4 as uuidv4 } from 'uuid'
session.setItem("sessionId", uuidv4()) //This creates the session ID.
$w.onReady(() => {
let sessionId = session.getItem("sessionId") //This retrieves the session ID
console.log(sessionId)
})
2 Likes