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

How to track logged in users using Google Tag Manager

Follower ✭ ✭ ☆
# 1
Follower ✭ ✭ ☆

 

 

I have a question regarding Google Analytics filters - Currently in our Google Analytics filters we don't have a way to track logged in users vs non-logged in users. There is a JavaScript object always on our pages containing a "isLoggedIn" property which is set to either "Logged In" or "Not Logged In" which we can check with JavaScript in a custom GTM tag, but we are not sure the best way to get this to show up in a Google Analytics filter. I found this resource (https://css-tricks.com/learning-use-google-analytics-effectively-codepen/) describing how to achieve this, but this solution does not consider Google Tag Manager, so we are worried it would cause a conflict if we implemented as this page describes.

 

Any recommendations for achieving this filter?

 

Your feedback/advice would be greatly appreciated.

 

Thanks!

Marked as Best Answer.
Solution
Accepted by topic author Bryan S
December 2016

Re: How to track logged in users using Google Tag Manager

[ Edited ]
Participant ✭ ✭ ✭
# 2
Participant ✭ ✭ ✭

Hi Bryan,

 

Here you'll find those steps that I would take in order to send this data to GA and filter or segment it later on:

 

1) Create a hit-scoped custom dimension in Google Analytics. Go to Google Analytics Admin -> Custom Definitions under the web property you want to set this up with, and create a new Custom Dimension of hit scope and make note of the index:

 

Screen Shot 2016-12-17 at 03.52.12.pngScreen Shot 2016-12-17 at 03.53.08.png

 

2) How you actually retrieve the "isLoggedIn" depends on how you expose it in your website. A good method is to populate it in datalayer by a server-side process, which renders it together with the rest of the page. If you do that, "isLoggedIn" will be cemented in the page template, and you can use it with your critical tags pretty easily.

 

If you use a datalayer method, so all you need to create is a Data Layer Variable that picks up the "isLoggedIn" from the data model, and returns the value stored within. Example:

 

Screen Shot 2016-12-17 at 03.55.02.png

 

 

 

3) Next, add this Variable you just created into all the tags you want. If you send it with every single hit then you can get a comprehensive analysis of what your logged in and logged out visitors do on your site. You can send it along with every pageview for example: 

 

Screen Shot 2016-12-17 at 03.58.40.png

 

4) You can use this dimension and those values in a segment or in a specific filter in Google Analytics. It's up to you how exactly you would like to do that.

 

Hope this helps. Let us know how it goes.

Taavi

How to track logged in users using Google Tag Manager

Follower ✭ ✭ ☆
# 3
Follower ✭ ✭ ☆

Thank you so much for your response. This seems like a good solution.

 

Thank you!

How to track logged in users using Google Tag Manager

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

I have a similar situation to Bryan S except I don't have the authentication status available on the page, just the userId, if the user is logged in. I have installed a Joomla plugin that passes the userId to the dataLayer. When I am in preview mode and login, the left column of the console shows the first event is user_loggedin. If I click on this event and look at Variables, I can see the value of the logged in user is in the variable userId.

 

I want to set a variable to show either authenticated or unAuthenticated BEFORE the pageview tag fires, but I am not having any luck.

 

Following your post, I did the following:

1) I created a trigger called "Authenticated User", type = custom event, event name = user_loggedin, fires on all custom events.

2) I created a DataLayer variable called "isAuthenticated".

3) Then I created a Tag called "PUSH - User Authentication", type = Cutstom HTML, and input this code:
<script>
dataLayer.push({
'isAuthenticated': 'authenticated',
});
</script>

 

All this works except the "Page View" event is complete before the "Message" from the "PUSH - User Authentication" tag. So the value for isAuthenticated is not updated before the Pageview is sent to UA, so my custom dimension is incorrect - undefined rather than "authenticated".

 

I have tried giving "PUSH - User Authentication" a higher Tag firing priority (9) than my "GA - Standard Pageview" tag (1). Didn't work.

 

I tried Tag sequencing with a Setup and Cleanup tag, but I still cannot get the isAuthenticated status set correctly BEFORE the Pageview.

 

Any suggestions?