How does one associate Google Analytics with a particular authenticated user? - google-analytics

What method would you use to associate tracking information in Google Analytics with a particular named user?
I want to be able to do custom reports, and ultimately drill down on usage by user.
EDIT
I was thinking that perhaps the EventTracking API would be able to help somehow.
Also, referring to this documentation.

You could add the user's username as a tracking/segmentation) variable...
pageTracker._setVar(username);
You can only use one _setVar per page, though...
http://www.google.com/support/analytics/bin/answer.py?answer=57045
http://groups.google.com/group/analytics-help-basics/browse_thread/thread/07e29dc610050971

Since Google Analytics isn't aware of users who are logged into your site you'd have to do that sort of tracking within your site's software itself. If there isn't some sort of plugin or extension out there already you'll probably have to write one yourself that keeps track of what your users do when their logged in.

I think you want Google Analytics - Custom Variables. You can set five variables per page, and there is support for variables you set persisting over session and cookie (aka "visitor") lifetime. Take note of the rules for overwriting previous values based upon slot and scope; the documentation explains this with some examples. You should probably include something in a click-wrapped privacy policy about tracking individual users this way; it's somewhat invasive, depending on the purpose of your website.
_gaq.push(['_setCustomVar',
1, // Slot number: [1-5], inclusive. Required.
'Username', // Custom variable name. Required.
username, // Custom variable value. Required.
2 // Scope:
// 1 = visitor/cookie-level, 2 = session-level, 3 = page-level.
// Optional, default=3.
]);

http://www.highlyrelevant.com/2011/03/25/how-to-add-edit-google-analytics-users-to-your-account/
This post was really helpful for me and my team. Not only does it show how to add users, but it also tells you how to edit existing users that aren't setup correctly.
Thanks!
Phil

Related

Accessing User ID as a variable in Google Tag Manager for mobile

I'm getting started with Google Tag Manager for Android/iOS, and can't find a way to access the User ID as a variable. I can access Firebase User Properties and Event Parameters just fine.
So far, I've tried setting it using FirebaseAnalytics.setUserId and trying to access it as a User Property called user_id / userId.
Some workarounds I've thought of:
Using a CustomVariableProvider (preferred)
Setting the User ID as an Event Parameter (this wouldn't work with built-in events)
I'm just trying to make sure there's no built-in way of doing this before I resort to workarounds. Thanks!
I was not able to find the User ID (or UID) in the list of built-in variables, see this screenshot
There is a built-in way, but it requires quite a sophisticated setup.
In GA version 4 the path is changed comparing to the previous version, where the same could be done much easier via "Tracking Info".
Here are the starting steps in GA4:
Open https://analytics.google.com/analytics/web
Bottom-left corner -> Admin -> Setup Assistant -> Advanced setup -> User ID
Follow the instruction
After that UserID will be available in GTM.
Video guide for exact steps: https://www.youtube.com/watch?v=TVJMFVOXFUQ

Request.auth.metadata in security rules?

I have a Firebase project where I'd like for users to be able to see when other users created their profiles. My initial hope was that I could use "user.metadata.creationTime" on the frontend to pass the date into the user's extra info document and verify that it is correct by having "request.resource.data.datecreated == request.auth.metadata.creationTime" as a Database Rule, but it looks like it is not possible according to the documentation.
Is there any way I can verify that the creation date is correct on the backend?
More info edit: Below is the code that is being triggered when a user creates a new account on my profile. The three values are displayed publicly. I'm creating a niche gear for sale page so being able to see when a user first created their account could be helpful when deciding if a seller is sketchy. I don't want someone to be able to make it seem like they have been around for longer than they have been.
db.collection('users').doc(user.uid).set({
username: "Username-156135",
bio: "Add a bio",
created: user.metadata.creationTime
});
Firestore rules:
match /users/{id} {
allow get;
allow create, update: if request.resource.data.username is string &&
request.resource.data.bio is string &&
request.resource.data.created == request.auth.metadata.creationTime;
}
user.metadata.creationTime, according to the API documentation is a string with no documented format. I suggest not using it. In fact, what you're trying to do seems impossible since that value isn't available in the API documentation for request.auth.
What I suggest you do instead is use a Firebase Auth onCreate trigger with Cloud Functions to automatically create that document with the current time as a proper timestamp. Then, in security rules, I wouldn't even give the user the ability to change that field, so you can be sure it was only ever set accurately by the trigger. You might be interested in this solution overall.

Google analytics api Get the userID / ClientID

I want to get the usage data of my customer out of google analytics, to make some usability analysis with it. For this, I need something that I can determine, which event was done by which user. Is there a possibility in a google analytics api to get this two parts linked?
You could add a user ID as a custom dimension, you'd probably want to set the scope to user.
https://support.google.com/analytics/answer/2709828?hl=en
This would allow you to connect up which users performed which actions.
Of course you can! :) I have used it in a lot of projects.
https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits
Example:
ga('send', {
hitType: 'event',
eventCategory: 'Video',
eventAction: 'play',
eventLabel: 'cats.mp4'
});
Since clientId has been made available through the API as ga:clientId you can use this value.
I would recommend using a custom User Id though - setting you own generated User Id in the script using the Universal Analytics User ID feature and in your backend db.
Also add the id to any link you send to your clients via email/sms/etc. that lands on your homepage to follow up on marketing performance.
You would need to have some javascript that grab the id and set it on the pageview. (like Linker, but adjusted for user id)
Note to anyone using the Universal Analytics User ID feature The values returned in ga:clientId is actually the userId Even more interessting. (As of time of writing) GA fails if you request clientId from a User ID view. So you should use a non-User ID view to get the User ID. :)

How to Track Store Locator Search terms in Google Universal Analytics

I am in the process of setting up enhanced Ecommerce for GA and have had a few requests of additional of what else the client would like to see in their reports. Once of which is
"Where can i see a report if the locations that a use types in when they use the store locator"
There is already an internal search functionality thats been set up and is tracking the search terms people are typing when looking for products, but i'm not sure if i would need to set this up as a second search terms report or if it's something different?
The URL of the page is different to the internal search results and is www.domain.com/store-locator#wales|GB|0|0|0
Any insight into this would be really helpful.
Thanks,
Roxi
As to me knowledge, you are not able to use bookmarks (#something) in GA for internal site search setup. Only GET and POST parameters are allowed. In your situation I think the best solution is to use GA events to send the data about used location each time the user is using this functionality. You need to include addition ga() function call to track those events. Info about how to set it up you could find here: event tracking. After setting things up, you will see all the info about number and type of called events in Behavior -> Events reports section in GA.
Example code:
<button onlick="var hash_location=window.location.hash;ga('send','event','Locator',has_location)">Click me</button>
With such function new event will be send to GA with Event Category=Locator and Event Action=hash in the url. You have some complicated hash, so most probably you need to extract first some info from this using regular expression. Example to get first item from |-separated list in the hash:
var pattern = new RegExp('[^#|]+');
var hash_location = pattern.exec(window.location.hash)[0];

Measuring goals for users who have never logged into my site before

I have a web app. The home page has two main actions:
Sign up to the application
Log into the application
I have a goal set up for sign-ups. I am trying to track the goal conversion rate of users who have never logged into the application before.
The problem I have at the moment is that the conversion rate is being skewed by users who are visiting the homepage simply to log in.
Is there a simple way of doing this?
Thanks very much,
Ben
For the kind of tracking you are looking for, there should be some coding on both your system and Google Analytics.
First, I would recommend you place into your system the intelligence to know the number of log-ins the user has made (As an example, a counter on your database).
Now, to implement that, you will need to set a Custom Var in Google Analytics in a visit level, to segment the users from the non-users, in that CustomVar, you can store both the user ID and the number of logins he has made.
This is the on the login page:
Your Code Should Look Like:
_gaq.push(['_setCustomVar',
1,
'Member Login',
'NUMBER OF LOGINS', // SET THIS FROM YOUR SYSTEM
2 //VISIT LEVEL Custom Var
]);
Remember that this code should go before tracking the pageview.
After setting this up, you should use Advanced Segments to check those specific users, one case could be: (Using the example above)
Setup an Advanced Segment that "Excludes" the Custom Variable (Key 1) - Mathing RegExp : .*
This will give you all the never-loged user access.
Something else you could do is set up Adv Segments to check on a specific number of logins
Setup an Advanced Segment that "Excludes" the Custom Variable (Key 1) - Mathing RegExp : [^1]
This will give you all the users that loged-in more than once.
You can find more info on Custom Vars here.

Resources