Analytics
4.5K members online now
4.5K members online now
Ask questions about filter set-up and issues with using filters in Google Analytics reports
 
Guide Me
star_border
Reply

Google Analytics session vs sessionStorage

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I'm trying to set a Custom Dimension for my users based on their login state. For various reasons I want to track 3 different states; non-users, signed up users and logged in users. Signed up users are those users who sign up during that session.


I'm using a filtered view based on this custom dimension. 

 

The Custom Dimension is a session-scope dimension and I set that with Tag Manager. This is the business logic.

 

function() {
 var status = "";
 if (!document.cookie.match("userId")) {
   status = "0";
   } else if (sessionStorage.getItem("signedUp")) {
   status = "3";
  }
 else {
   status = "1";
  }
 return status;
}

Then on my sign up conversion pages, I do 

sessionStorage.setItem("signedUp",true);

I send this Custom Dimension on a Window Loaded and set this sessionStorage item on Page view so that sessionStorage should be set correctly before the view is sent to Analytics. 

 

In a new view I'm creating I'll create a filter to exclude sessions with the status logged in ("1" in the example above). Because I'm filtering out logged-in users, it's very important that sessionStorage persists until that Analytics session persists, because otherwise I'll filter out a signed up (=converted) user.

 

So; what is the best way to make sure I'm tracking signed up users correctly in my case? I'm trying to avoid a situation where the Analytics session persists for longer than my sessionStorage.

 

Google Analytics session vs sessionStorage

[ Edited ]
Explorer ✭ ✭ ✭
# 2
Explorer ✭ ✭ ✭

Hi, @Ottomatias P

I suppose that setting these three values into one dimension could be misleading and complicating. Consider using one dimension for logged In status and other dimension for Sing Up status. Another approach could be sending Sign Up data as an event and setting event-based Goal for this event. Then you could easily filter your users with condition "Goal X completions > 0" and also let your signed up users to log in within the same session as they signed up.

If you're knowingly prefer custom dimension for signed up status consider using re-writable 30 mins cookie to imitate GA sessions logic instead of sessionStorage.