NTP-60143 | Alfred rearch (#16237)

Co-authored-by: amansingh <aman.s@navi.com>
This commit is contained in:
Sayed Owais Ali
2025-05-27 12:32:41 +05:30
committed by GitHub
parent ca74760253
commit ecf0e48daf
58 changed files with 416 additions and 419 deletions

View File

@@ -0,0 +1,10 @@
/*
*
* * Copyright © 2025 by Navi Technologies Limited
* * All rights reserved. Strictly confidential
*
*/
package com.navi.analytics.model
data class ErrorLog(val statusCode: String? = null, val message: String? = null)

View File

@@ -0,0 +1,205 @@
/*
*
* * Copyright © 2024-2025 by Navi Technologies Limited
* * All rights reserved. Strictly confidential
*
*/
package com.navi.analytics.utils
import android.app.Dialog
import android.content.Context
import android.view.MotionEvent
import android.view.View
import com.navi.alfred.config.AlfredConfig
import com.navi.alfred.core.AlfredManager
import com.navi.alfred.core.handler.AlfredEventHandlerImpl
import com.navi.alfred.model.EventType
import com.navi.alfred.network.AlfredAnalyticsManager
import com.navi.alfred.network.AlfredAnalyticsProvider
import com.navi.alfred.utils.log
import com.navi.analytics.model.AnalyticsConfiguration
import com.navi.analytics.model.ErrorLog
import com.navi.base.utils.EMPTY
import com.navi.base.utils.NetWatchManger
import com.navi.base.utils.isNotNullAndNotEmpty
import okhttp3.Request
import okhttp3.Response
import org.json.JSONObject
object AlfredFacade : AlfredAnalyticsProvider {
private var isAlfredEnabled: Boolean = false
private inline fun executeIfAlfredEnabled(action: () -> Unit) {
if (!isAlfredEnabled) {
return
}
action()
}
private inline fun executeIfAlfredAndRepoInitialized(action: () -> Unit) {
if (!isAlfredEnabled || !AlfredManager.isSensitiveComposeRepositoryInitialized()) {
return
}
action()
}
fun init(analyticsConfiguration: AnalyticsConfiguration, context: Context) {
isAlfredEnabled = true
val alfredConfig =
AlfredConfig(
appName = analyticsConfiguration.appInfo.appName,
appVersionName = analyticsConfiguration.appInfo.appVersionName,
appVersionCode = analyticsConfiguration.appInfo.appVersionCode,
flavor = analyticsConfiguration.flavor,
disableAlfredLogs = analyticsConfiguration.disableAlfredLogs,
apiKey = analyticsConfiguration.alfredKey,
)
AlfredManager.init(
config = alfredConfig,
context = context,
criticalJourneyResponseCode = CRITICAL_JOURNEY_RESPONSE_CODE,
criticalJourneyResponseMessage = CRITICAL_JOURNEY_RESPONSE_MESSAGE,
)
AlfredAnalyticsManager.init(alfredAnalyticsProvider = this)
}
fun handleNegativeExperienceEvent(
eventType: EventType,
eventProperties: MutableMap<String, String>,
) {
executeIfAlfredEnabled {
AlfredEventHandlerImpl.handleNegativeExperienceEvent(
eventType = eventType,
eventProperties = eventProperties,
)
}
}
fun handleTouchEvent(motionEvent: MotionEvent?, screenName: String, moduleName: String) {
executeIfAlfredEnabled {
AlfredEventHandlerImpl.handleTouchEvent(
currentTouchEvent = motionEvent,
screenName = screenName,
moduleName = moduleName,
)
}
}
fun setUserLocation(longitude: Double, latitude: Double) {
executeIfAlfredEnabled {
AlfredManager.setLocation(longitude = longitude, latitude = latitude)
}
}
fun setAlfredDialog(dialog: Dialog? = null) {
executeIfAlfredEnabled { AlfredManager.setDialog(dialog) }
}
fun setCurrentScreenName(screenName: String) {
executeIfAlfredEnabled { AlfredManager.setCurrentScreenName(screenName) }
}
fun setBottomSheetView(bottomSheetView: View) {
executeIfAlfredEnabled { AlfredManager.setBottomSheetView(bottomSheetView) }
}
fun clearBottomSheetView() {
executeIfAlfredEnabled { AlfredManager.clearBottomSheetView() }
}
fun getAlfredSessionId(): String {
return AlfredManager.getAlfredSessionId()
}
fun setUserId(userId: String) {
executeIfAlfredEnabled { AlfredManager.setUserId(userId) }
}
fun removeSensitiveComposable(id: String) {
executeIfAlfredAndRepoInitialized {
AlfredManager.sensitiveComposeRepository.removeSensitiveComposable(id)
}
}
fun maskSensitiveUiTronComposable(
id: String,
left: Float?,
top: Float?,
right: Float?,
bottom: Float?,
rootView: View?,
) {
executeIfAlfredAndRepoInitialized {
AlfredManager.sensitiveComposeRepository.maskSensitiveUiTronComposable(
id,
left,
top,
right,
bottom,
rootView,
)
}
}
fun blurSensitiveScreen(blur: Boolean) {
executeIfAlfredAndRepoInitialized {
AlfredManager.sensitiveComposeRepository.blurSensitiveScreen(blur)
}
}
fun updateCriticalUserJourneyStatus(status: Boolean) {
executeIfAlfredEnabled { AlfredManager.updateCriticalUserJourneyStatus(status) }
}
override fun sendApiLog(request: Request, response: Response, exception: Exception?) {
executeIfAlfredEnabled {
if (NetWatchManger.isQaRelease()) {
try {
val responseString = response.peekBody(Long.MAX_VALUE).string()
val responseData =
if (responseString.isNotNullAndNotEmpty()) {
JSONObject(responseString)
} else {
null
}
NetWatchManger.buildLogMessage(
responseData = responseData,
request = response.request,
response = response,
logType = NetWatchManger.ReleaseLogType.NETWORK_LOG.name,
errorMessage =
ErrorLog(
statusCode = response.code.toString(),
message = response.message,
),
moduleName = ALFRED_MODULE,
)
} catch (e: Exception) {
e.log()
}
}
if (exception != null) {
NaviAnalyticsHelper.recordException(exception)
NaviTrackEvent.trackEventOnClickStream(
NETWORK_CRASH,
mapOf(
Pair(MESSAGE_TEXT, exception.message.orEmpty()),
Pair(CODE_TEXT, response.code.toString()),
Pair(API_URL, request.url.toString()),
Pair(VERTICAL, request.headers[X_TARGET] ?: EMPTY),
Pair(APP_REQUEST_ID, request.headers[APP_REQUEST_ID] ?: EMPTY),
),
)
}
}
}
override fun sendEvent(eventName: String, eventAttributes: MutableMap<String, String>?) {
executeIfAlfredEnabled {
NaviTrackEvent.trackEvent(eventName = eventName, eventValues = eventAttributes)
}
}
}

View File

@@ -32,3 +32,12 @@ const val CONTEXT = "context"
const val OPTION_SELECTED = "option_selected"
const val CRITICAL_JOURNEY_RESPONSE_CODE = 27
const val CRITICAL_JOURNEY_RESPONSE_MESSAGE = "Critical journey is active"
const val APP_VERSION_CODE = "appVersionCode"
const val X_TARGET = "X-Target"
const val APP_REQUEST_ID = "appRequestId"
const val NETWORK_CRASH = "network_crash"
const val MESSAGE_TEXT = "message"
const val CODE_TEXT = "code"
const val API_URL = "apiUrl"
const val VERTICAL = "vertical"
const val ALFRED_MODULE = "Alfred"

View File

@@ -11,8 +11,6 @@ import android.app.Application
import android.content.Context
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.navi.alfred.AlfredConfig
import com.navi.alfred.AlfredManager
import com.navi.analytics.BuildConfig
import com.navi.analytics.appsflyer.AppsFlyerUtil
import com.navi.analytics.firebase.FcmAnalyticsUtil
@@ -52,21 +50,7 @@ object NaviTrackEvent {
.setEventInterval(analyticsConfiguration.pulseConfig.eventInterval)
.build()
if (analyticsConfiguration.disableAlfred.not()) {
val alfredConfig =
AlfredConfig(
appName = analyticsConfiguration.appInfo.appName,
appVersionName = analyticsConfiguration.appInfo.appVersionName,
appVersionCode = analyticsConfiguration.appInfo.appVersionCode,
flavor = analyticsConfiguration.flavor,
disableAlfredLogs = analyticsConfiguration.disableAlfredLogs,
apiKey = analyticsConfiguration.alfredKey,
)
AlfredManager.init(
alfredConfig,
appContext,
criticalJourneyResponseCode = CRITICAL_JOURNEY_RESPONSE_CODE,
criticalJourneyResponseMessage = CRITICAL_JOURNEY_RESPONSE_MESSAGE,
)
AlfredFacade.init(analyticsConfiguration, appContext)
}
PulseManager.init(
sdkConfig = pulseConfig,
@@ -161,7 +145,7 @@ object NaviTrackEvent {
FcmAnalyticsUtil.analytics.setUserId(id)
AppsFlyerUtil.instance.setCustomerId(id)
PulseManager.setUserId(id)
AlfredManager.setUserId(id)
AlfredFacade.setUserId(id)
}
fun setSessionId(sessionId: String) {
@@ -186,7 +170,7 @@ object NaviTrackEvent {
fun trackLocation(latitude: Double, longitude: Double) {
PulseSDKConfig.setLocation(latitude, longitude)
AlfredManager.setUserLocation(latitude, longitude)
AlfredFacade.setUserLocation(latitude, longitude)
}
fun setAdvertisingId(googleAdvertisingId: String) {