mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(analytics): authentication analytics (#4429)
Co-authored-by: Sampras Lopes <lsampras@pm.me> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
111
crates/api_models/src/analytics/auth_events.rs
Normal file
111
crates/api_models/src/analytics/auth_events.rs
Normal file
@ -0,0 +1,111 @@
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
use super::NameDescription;
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Hash,
|
||||
PartialEq,
|
||||
Eq,
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
strum::Display,
|
||||
strum::EnumIter,
|
||||
strum::AsRefStr,
|
||||
)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum AuthEventMetrics {
|
||||
ThreeDsSdkCount,
|
||||
AuthenticationAttemptCount,
|
||||
AuthenticationSuccessCount,
|
||||
ChallengeFlowCount,
|
||||
FrictionlessFlowCount,
|
||||
ChallengeAttemptCount,
|
||||
ChallengeSuccessCount,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Hash,
|
||||
PartialEq,
|
||||
Eq,
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
strum::Display,
|
||||
strum::EnumIter,
|
||||
strum::AsRefStr,
|
||||
)]
|
||||
pub enum AuthEventFlows {
|
||||
PostAuthentication,
|
||||
}
|
||||
|
||||
pub mod metric_behaviour {
|
||||
pub struct ThreeDsSdkCount;
|
||||
pub struct AuthenticationAttemptCount;
|
||||
pub struct AuthenticationSuccessCount;
|
||||
pub struct ChallengeFlowCount;
|
||||
pub struct FrictionlessFlowCount;
|
||||
pub struct ChallengeAttemptCount;
|
||||
pub struct ChallengeSuccessCount;
|
||||
}
|
||||
|
||||
impl From<AuthEventMetrics> for NameDescription {
|
||||
fn from(value: AuthEventMetrics) -> Self {
|
||||
Self {
|
||||
name: value.to_string(),
|
||||
desc: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, Eq)]
|
||||
pub struct AuthEventMetricsBucketIdentifier {
|
||||
pub time_bucket: Option<String>,
|
||||
}
|
||||
|
||||
impl AuthEventMetricsBucketIdentifier {
|
||||
pub fn new(time_bucket: Option<String>) -> Self {
|
||||
Self { time_bucket }
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for AuthEventMetricsBucketIdentifier {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.time_bucket.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for AuthEventMetricsBucketIdentifier {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
let mut left = DefaultHasher::new();
|
||||
self.hash(&mut left);
|
||||
let mut right = DefaultHasher::new();
|
||||
other.hash(&mut right);
|
||||
left.finish() == right.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct AuthEventMetricsBucketValue {
|
||||
pub three_ds_sdk_count: Option<u64>,
|
||||
pub authentication_attempt_count: Option<u64>,
|
||||
pub authentication_success_count: Option<u64>,
|
||||
pub challenge_flow_count: Option<u64>,
|
||||
pub challenge_attempt_count: Option<u64>,
|
||||
pub challenge_success_count: Option<u64>,
|
||||
pub frictionless_flow_count: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct MetricsBucketResponse {
|
||||
#[serde(flatten)]
|
||||
pub values: AuthEventMetricsBucketValue,
|
||||
#[serde(flatten)]
|
||||
pub dimensions: AuthEventMetricsBucketIdentifier,
|
||||
}
|
||||
@ -72,18 +72,12 @@ pub enum SdkEventDimensions {
|
||||
pub enum SdkEventMetrics {
|
||||
PaymentAttempts,
|
||||
PaymentMethodsCallCount,
|
||||
ThreeDsMethodInvokedCount,
|
||||
ThreeDsMethodSkippedCount,
|
||||
ThreeDsMethodSuccessfulCount,
|
||||
ThreeDsMethodUnsuccessfulCount,
|
||||
AuthenticationUnsuccessfulCount,
|
||||
ThreeDsChallengeFlowCount,
|
||||
ThreeDsFrictionlessFlowCount,
|
||||
SdkRenderedCount,
|
||||
SdkInitiatedCount,
|
||||
PaymentMethodSelectedCount,
|
||||
PaymentDataFilledCount,
|
||||
AveragePaymentTime,
|
||||
LoadTime,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
@ -114,6 +108,7 @@ pub enum SdkEventNames {
|
||||
DisplayBankTransferInfoPage,
|
||||
DisplayQrCodeInfoPage,
|
||||
AuthenticationCall,
|
||||
AuthenticationCallInit,
|
||||
ThreeDsMethodCall,
|
||||
ThreeDsMethodResult,
|
||||
ThreeDsMethod,
|
||||
@ -124,18 +119,12 @@ pub enum SdkEventNames {
|
||||
pub mod metric_behaviour {
|
||||
pub struct PaymentAttempts;
|
||||
pub struct PaymentMethodsCallCount;
|
||||
pub struct ThreeDsMethodInvokedCount;
|
||||
pub struct ThreeDsMethodSkippedCount;
|
||||
pub struct ThreeDsMethodSuccessfulCount;
|
||||
pub struct ThreeDsMethodUnsuccessfulCount;
|
||||
pub struct AuthenticationUnsuccessfulCount;
|
||||
pub struct ThreeDsChallengeFlowCount;
|
||||
pub struct ThreeDsFrictionlessFlowCount;
|
||||
pub struct SdkRenderedCount;
|
||||
pub struct SdkInitiatedCount;
|
||||
pub struct PaymentMethodSelectedCount;
|
||||
pub struct PaymentDataFilledCount;
|
||||
pub struct AveragePaymentTime;
|
||||
pub struct LoadTime;
|
||||
}
|
||||
|
||||
impl From<SdkEventMetrics> for NameDescription {
|
||||
@ -215,18 +204,12 @@ impl PartialEq for SdkEventMetricsBucketIdentifier {
|
||||
pub struct SdkEventMetricsBucketValue {
|
||||
pub payment_attempts: Option<u64>,
|
||||
pub payment_methods_call_count: Option<u64>,
|
||||
pub average_payment_time: Option<f64>,
|
||||
pub average_payment_time: Option<u64>,
|
||||
pub load_time: Option<u64>,
|
||||
pub sdk_rendered_count: Option<u64>,
|
||||
pub sdk_initiated_count: Option<u64>,
|
||||
pub payment_method_selected_count: Option<u64>,
|
||||
pub payment_data_filled_count: Option<u64>,
|
||||
pub three_ds_method_invoked_count: Option<u64>,
|
||||
pub three_ds_method_skipped_count: Option<u64>,
|
||||
pub three_ds_method_successful_count: Option<u64>,
|
||||
pub three_ds_method_unsuccessful_count: Option<u64>,
|
||||
pub authentication_unsuccessful_count: Option<u64>,
|
||||
pub three_ds_challenge_flow_count: Option<u64>,
|
||||
pub three_ds_frictionless_flow_count: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
|
||||
Reference in New Issue
Block a user