In cloudscribe Core we use the GoogleAnalyticsTagHelper, GoogleAnalyticsHelper, and GoogleAnalyticsApiService provided by the cloudscribe.Web.Common library to track basic things like page views and also to track user account events such as Login Submit, Login Success, Login Failure, Registration Submit, Registration Success, and Registration Failure. We also track whether the login or registration event used a social login service such as Facebook or Twitter, or Google or Microsoft or whether it was just a local account.
The implementation for tracking these account events was basically using the approach from this tutorial.
The tutorial linked above is a good source also to begin learning about custom dimensions and metrics in google analytics. Our implementation uses pretty much the same dimension and metrics indexes used in that article. If you don't already have custom dimensions and metrics established in your google analytics then you should also be able to use the same indexes, but if you do already have some custom dimensions and metrics configured then there is a good chance the index numbers we used would conflict with ones you are already using, so we made them configurable in case you need to change them to use different index numbers for login and registration events.
Setting Up Custom Dimensions and Metrics in Google Analytics
To get the most benefit out of the built in user account tracking, you need to setup the corresponding custom dimensions and metrics in your google analytics property settings. Notice the "Custom Dimensions" and "Custom Metrics" menu items in the screen shot below.
Setup your custom dimensions as shown in the following screen shot:
and setup your custom metrics as shown in this screen shot:
Overriding the Indexes for Dimensions and Metrics
If you do already have custom dimensions and metrics using the same indexes, you can customize the indexes used by cloudscribe Core. The configurable settings are all shown below with their default values. If using cloudscribe Core you can update them in appsettings.json to whatever values you want.
"GoogleAnalyticsOptions": {
"TrackUserId": "true",
"UserIdDimensionIndex": "1",
"RegisteredUserDimensionIndex": "2",
"LoginRegisterSourceDimenstionIndex": "3",
"RegisterSuccessMetricIndex": "1",
"RegisterFailMetricIndex": "2",
"RegisterSubmitMetricIndex": "3",
"LoginSuccessMetricIndex": "4",
"LoginFailMetricIndex": "5",
"LoginSubmitMetricIndex": "6",
"LoginRegisterEventCategory": "Login and Registration",
"LoginSuccessEventAction": "Login Success",
"LoginFailEventAction": "Login Fail",
"LoginSubmitEventAction": "Login Submit",
"RegisterSuccessEventAction": "Register Success",
"RegisterFailEventAction": "Register Fail",
"RegisterSubmitEventAction": "Register Submit"
}
As you can see, you can also customize the category and action names used in the tracking. Also depending on your privacy policy you may want to set TrackUserId to false. Google forbids capturing any personal identifying user information directly in google analytics but you can capture a user id that corresponds to the user id for the user in your own website database and you are allowed to capture that in google analytics and there are advantages in doing so. You do have to enable the UserID feature in your google analytics account and that will create a view on your data that is filtered to only requests with a userid, for that reason you should also always keep a set of views enabled that don't filter use that filter.
Even though you can't store user names or identifying information in google analytics, if you are capturing userid, it is possible using a Chrome extension to associate a CSV file that has the userid along with other information so that you can view the actual users in your reports.
Next Steps
Now that you have setup custom dimensions and metrics for user account events, you can use those for setting goals in google analytics. There are lots of tutorials online to learn about setting goals in google analytics.
In Summary, cloudscribe Core has built in tracking of page views and account events such as login and registration. You can see the actual code we use for tracking account events here. You can also track other custom events in your own custom features using similar techniques. See the Easy Google Analytics article in the documentation for cloudscribe.Web.Common to learn more.