Search code examples
javascriptgoogle-analyticsanalytics

google analytics javascript application


I have a javascript application (no refreshes).

I'm trying to setup google analytics to track events for each user, so that it would be possible to see which user performed which event in the application.

I think I'm supposed to set a custom var of a session type? But not sure how to go about it. I'm looking for an example, thanks.

The question is:

How do I set a session level user so that all the events that that user initiates are set as that by the user. I have the user's username saved as a javascript variable. I just want to attach that variable to the google analytics session.


Solution

  • If it's their username then that is a violation of Google Analytics terms of service. See number 7 PRIVACY.

    Custom vars can be used to determine user type and/or login status. See Session-level Custom Variables

    For example, if your website offers users the ability to login, you can use a custom variable scoped to the session level for user login status. In that way, you can segment visits by those from logged in members versus anonymous visitors.

    Example:

    While the username or user ID is not directly PII, if it is used to tie to a person from a backend system…that’s a violation of the Terms of Service.