public Task HandleLockout(UserLoginResult result) { if (!string.IsNullOrEmpty(_currentSite.GoogleAnalyticsProfileId)) { var e = new GoogleAnalyticsEvent(); e.Category = _options.LoginRegisterEventCategory; e.Action = _options.LoginFailEventAction; var source = "Onsite"; if (result.ExternalLoginInfo != null) { source = result.ExternalLoginInfo.LoginProvider; } e.Label = source; e.Value = "Account lockout"; if (_options.TrackUserId && result.User != null) { e.Fields.Add(new KeyValuePair <string, string>("dimension" + _options.UserIdDimensionIndex.ToInvariantString(), result.User.Id.ToString())); } e.Fields.Add(new KeyValuePair <string, string>("dimension" + _options.LoginRegisterSourceDimenstionIdex.ToInvariantString(), source)); e.Fields.Add(new KeyValuePair <string, string>("metric" + _options.LoginFailMetricIndex.ToInvariantString(), "1")); AddGoogleAnalyticsEvent(e); } return(Task.FromResult(0)); }
private void AddGoogleAnalyticsEvent(GoogleAnalyticsEvent ev) { //these are detected by the google analytics taghelper var tempData = GetTempData(); if (tempData != null) { tempData.AddEvent(ev); } }
private async Task HandleRegisterSuccess(UserLoginResult result) { var source = "Onsite"; if (result.ExternalLoginInfo != null) { source = result.ExternalLoginInfo.LoginProvider; } if (_options.TrackSocialLoginServerSide && result.ExternalLoginInfo != null) { var props = _analyticsApi.GetStandardProps(_contextAccessor.HttpContext); var dimensionAndMetrics = new List <KeyValuePair <string, string> >(); if (_options.TrackUserId && result.User != null) { dimensionAndMetrics.Add(new KeyValuePair <string, string>("cd" + _options.UserIdDimensionIndex.ToInvariantString(), result.User.Id.ToString())); } dimensionAndMetrics.Add(new KeyValuePair <string, string>("cd" + _options.RegisteredUserDimensionIdex.ToInvariantString(), "Yes")); dimensionAndMetrics.Add(new KeyValuePair <string, string>("cd" + _options.LoginRegisterSourceDimenstionIdex.ToInvariantString(), source)); dimensionAndMetrics.Add(new KeyValuePair <string, string>("cm" + _options.RegisterSuccessMetricIndex.ToInvariantString(), "1")); await _analyticsApi.TrackEvent( _currentSite.GoogleAnalyticsProfileId, props.ClientId, null, props.Host, _options.LoginRegisterEventCategory, _options.RegisterSuccessEventAction, source, null, props.IpAddress, props.UserAgent, dimensionAndMetrics ); } else { var e = new GoogleAnalyticsEvent(); e.Category = _options.LoginRegisterEventCategory; e.Action = _options.RegisterSuccessEventAction; e.Label = source; if (_options.TrackUserId && result.User != null) { e.Fields.Add(new KeyValuePair <string, string>("dimension" + _options.UserIdDimensionIndex.ToInvariantString(), result.User.Id.ToString())); } e.Fields.Add(new KeyValuePair <string, string>("dimension" + _options.RegisteredUserDimensionIdex.ToInvariantString(), "Yes")); e.Fields.Add(new KeyValuePair <string, string>("dimension" + _options.LoginRegisterSourceDimenstionIdex.ToInvariantString(), source)); e.Fields.Add(new KeyValuePair <string, string>("metric" + _options.RegisterSuccessMetricIndex.ToInvariantString(), "1")); AddGoogleAnalyticsEvent(e); } }
public async Task HandleRegisterFail(string source, string reason) { if (!string.IsNullOrEmpty(_currentSite.GoogleAnalyticsProfileId)) { if (_options.TrackSocialLoginServerSide && source != "Onsite") { var props = _analyticsApi.GetStandardProps(_contextAccessor.HttpContext); var dimensionAndMetrics = new List <KeyValuePair <string, string> >(); dimensionAndMetrics.Add(new KeyValuePair <string, string>("cd" + _options.LoginRegisterSourceDimenstionIdex.ToInvariantString(), source)); dimensionAndMetrics.Add(new KeyValuePair <string, string>("cm" + _options.RegisterFailMetricIndex.ToInvariantString(), "1")); await _analyticsApi.TrackEvent( _currentSite.GoogleAnalyticsProfileId, props.ClientId, null, props.Host, _options.LoginRegisterEventCategory, _options.RegisterFailEventAction, source, reason, props.IpAddress, props.UserAgent, dimensionAndMetrics ); } else { var e = new GoogleAnalyticsEvent(); e.Category = _options.LoginRegisterEventCategory; e.Action = _options.RegisterFailEventAction; e.Label = source; e.Value = reason; e.Fields.Add(new KeyValuePair <string, string>("dimension" + _options.LoginRegisterSourceDimenstionIdex.ToInvariantString(), source)); e.Fields.Add(new KeyValuePair <string, string>("metric" + _options.RegisterFailMetricIndex.ToInvariantString(), "1")); AddGoogleAnalyticsEvent(e); } } //return Task.FromResult(0); }
public async Task HandleLoginNotAllowed(UserLoginResult result) { if (!string.IsNullOrEmpty(_currentSite.GoogleAnalyticsProfileId)) { if (result.IsNewUserRegistration) { // first record successful registration await HandleRegisterSuccess(result); var source = "Onsite"; if (result.ExternalLoginInfo != null) { source = result.ExternalLoginInfo.LoginProvider; } var reason = "Login not allowed"; if (result.MustAcceptTerms) { reason = "User must accept terms of use"; } if (result.NeedsPhoneConfirmation) { reason = "Needs phone number confirmation"; } if (result.NeedsEmailConfirmation) { reason = "Needs email confirmation"; } if (result.NeedsAccountApproval) { reason = "Needs account approval"; } if (_options.TrackSocialLoginServerSide && result.ExternalLoginInfo != null) { var props = _analyticsApi.GetStandardProps(_contextAccessor.HttpContext); var dimensionAndMetrics = new List <KeyValuePair <string, string> >(); if (_options.TrackUserId && result.User != null) { dimensionAndMetrics.Add(new KeyValuePair <string, string>("cd" + _options.UserIdDimensionIndex.ToInvariantString(), result.User.Id.ToString())); } dimensionAndMetrics.Add(new KeyValuePair <string, string>("cd" + _options.LoginRegisterSourceDimenstionIdex.ToInvariantString(), source)); dimensionAndMetrics.Add(new KeyValuePair <string, string>("cm" + _options.LoginFailMetricIndex.ToInvariantString(), "1")); await _analyticsApi.TrackEvent( _currentSite.GoogleAnalyticsProfileId, props.ClientId, null, props.Host, _options.LoginRegisterEventCategory, _options.LoginFailEventAction, source, reason, props.IpAddress, props.UserAgent, dimensionAndMetrics ); } else { var e = new GoogleAnalyticsEvent(); e.Category = _options.LoginRegisterEventCategory; e.Action = _options.LoginFailEventAction; e.Label = source; e.Value = reason; if (_options.TrackUserId && result.User != null) { e.Fields.Add(new KeyValuePair <string, string>("dimension" + _options.UserIdDimensionIndex.ToInvariantString(), result.User.Id.ToString())); } e.Fields.Add(new KeyValuePair <string, string>("dimension" + _options.LoginRegisterSourceDimenstionIdex.ToInvariantString(), source)); e.Fields.Add(new KeyValuePair <string, string>("metric" + _options.LoginFailMetricIndex.ToInvariantString(), "1")); AddGoogleAnalyticsEvent(e); } } } // return Task.FromResult(0); }