NTP-8036-Removed Moengage init for tracking (#13183)
This commit is contained in:
@@ -1,169 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2020-2023 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
|
||||
package com.navi.analytics.moengage
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.moe.pushlibrary.MoEHelper
|
||||
import com.moengage.core.DataCenter
|
||||
import com.moengage.core.MoEngage
|
||||
import com.moengage.core.Properties
|
||||
import com.moengage.core.config.FcmConfig
|
||||
import com.moengage.core.config.InAppConfig
|
||||
import com.moengage.core.config.LogConfig
|
||||
import com.moengage.core.config.NotificationConfig
|
||||
import com.moengage.firebase.MoEFireBaseHelper
|
||||
import com.moengage.inapp.MoEInAppHelper
|
||||
import com.moengage.pushbase.MoEPushHelper
|
||||
import com.navi.analytics.BuildConfig
|
||||
import com.navi.analytics.model.MoengageData
|
||||
import com.navi.analytics.model.UserLocation
|
||||
import java.lang.ref.WeakReference
|
||||
import timber.log.Timber
|
||||
|
||||
object MoengageUtil {
|
||||
fun init(
|
||||
appContext: Application,
|
||||
moengageData: MoengageData,
|
||||
inAppOptOutScreens: MutableSet<Class<*>>
|
||||
) {
|
||||
try {
|
||||
val moEngage =
|
||||
MoEngage.Builder(appContext, moengageData.moengageKey)
|
||||
.setDataCenter(DataCenter.DATA_CENTER_3)
|
||||
.configureNotificationMetaData(
|
||||
NotificationConfig(moengageData.smallIconId, moengageData.largeIconId)
|
||||
)
|
||||
.configureLogs(LogConfig())
|
||||
.configureFcm(FcmConfig(isRegistrationEnabled = true))
|
||||
.configureInApps(InAppConfig(inAppOptOutScreens))
|
||||
.build()
|
||||
MoEngage.initialiseDefaultInstance(moEngage)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun trackScreenName(
|
||||
screenName: String,
|
||||
eventValues: Map<String, Any>? = null,
|
||||
context: Context
|
||||
) {
|
||||
trackEvent(screenName, eventValues, context)
|
||||
}
|
||||
|
||||
fun trackEvent(eventName: String, eventValues: Map<String, Any>? = null, context: Context) {
|
||||
try {
|
||||
val properties = Properties()
|
||||
eventValues?.let { events ->
|
||||
for ((key, value) in events) {
|
||||
properties.addAttribute(key, value)
|
||||
}
|
||||
}
|
||||
MoEHelper.getInstance(context).trackEvent(eventName, properties)
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d("NAVI_MO_EVENT", eventName + " : " + eventValues.toString())
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun setUserId(id: String, context: Context) {
|
||||
try {
|
||||
MoEHelper.getInstance(context).setUniqueId(id) // Pass Unique user id
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun showInApp(context: WeakReference<Context>) {
|
||||
try {
|
||||
context.get()?.let { MoEInAppHelper.getInstance().showInApp(it) }
|
||||
} catch (e: Exception) {}
|
||||
}
|
||||
|
||||
fun logoutUser(context: Context) {
|
||||
try {
|
||||
MoEHelper.getInstance(context).logoutUser()
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun setUserAttributes(
|
||||
context: Context,
|
||||
name: String?,
|
||||
phoneNumber: String?,
|
||||
email: String?,
|
||||
maritalStatus: String?,
|
||||
pinCode: String?,
|
||||
employmentType: String?,
|
||||
companyName: String?,
|
||||
monthlyIncomeAmount: Double?,
|
||||
gender: String?
|
||||
) {
|
||||
try {
|
||||
val helper = MoEHelper.getInstance(context)
|
||||
if (!name.isNullOrBlank()) helper.setFirstName(name.orEmpty())
|
||||
if (!phoneNumber.isNullOrBlank()) helper.setNumber(phoneNumber.orEmpty())
|
||||
if (!email.isNullOrBlank()) helper.setEmail(email.orEmpty())
|
||||
if (!maritalStatus.isNullOrBlank())
|
||||
helper.setUserAttribute(MARITAL_STATUS, maritalStatus.orEmpty())
|
||||
if (!pinCode.isNullOrBlank()) helper.setUserAttribute(PIN_CODE, pinCode.orEmpty())
|
||||
if (!employmentType.isNullOrBlank())
|
||||
helper.setUserAttribute(EMPLYOMENT_TYPE, employmentType.orEmpty())
|
||||
if (!companyName.isNullOrBlank())
|
||||
helper.setUserAttribute(COMPANY_NAME, companyName.orEmpty())
|
||||
if (monthlyIncomeAmount != null)
|
||||
helper.setUserAttribute(MONTHLY_INCOME, monthlyIncomeAmount)
|
||||
if (gender.isNullOrBlank().not()) helper.setUserAttribute(GENDER, gender.orEmpty())
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun setLatLongAttribute(location: UserLocation?, context: Context) {
|
||||
try {
|
||||
location?.let {
|
||||
val helper = MoEHelper.getInstance(context)
|
||||
if (!location.latitude.isNullOrBlank() && !location.latitude.isNullOrBlank())
|
||||
helper.setUserLocation(
|
||||
location.latitude.orEmpty().toDouble(),
|
||||
location.longitude.orEmpty().toDouble()
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun passPushToken(context: Context, newToken: String) {
|
||||
MoEFireBaseHelper.getInstance().passPushToken(context, newToken)
|
||||
}
|
||||
|
||||
fun isFromMoEngagePlatform(gcmPayLoad: Map<String, String>): Boolean {
|
||||
return MoEPushHelper.getInstance().isFromMoEngagePlatform(gcmPayLoad)
|
||||
}
|
||||
|
||||
fun isSilentPush(gcmPayLoad: Map<String, String>): Boolean {
|
||||
return MoEPushHelper.getInstance().isSilentPush(gcmPayLoad)
|
||||
}
|
||||
|
||||
fun passPushPayload(applicationContext: Context, gcmPayLoad: MutableMap<String, String>) {
|
||||
return MoEFireBaseHelper.getInstance().passPushPayload(applicationContext, gcmPayLoad)
|
||||
}
|
||||
|
||||
private const val MARITAL_STATUS = "marital_status"
|
||||
private const val PIN_CODE = "pin_code"
|
||||
private const val EMPLYOMENT_TYPE = "employment_type"
|
||||
private const val COMPANY_NAME = "company_name"
|
||||
private const val MONTHLY_INCOME = "monthly_income"
|
||||
private const val GENDER = "gender"
|
||||
}
|
||||
@@ -17,8 +17,6 @@ import com.navi.analytics.BuildConfig
|
||||
import com.navi.analytics.appsflyer.AppsFlyerUtil
|
||||
import com.navi.analytics.firebase.FcmAnalyticsUtil
|
||||
import com.navi.analytics.model.AnalyticsConfiguration
|
||||
import com.navi.analytics.model.UserLocation
|
||||
import com.navi.analytics.moengage.MoengageUtil
|
||||
import com.navi.analytics.utils.NaviAnalyticsHelper.isEventWhiteListedForAppsflyer
|
||||
import com.navi.base.model.AnalyticsEvent
|
||||
import com.navi.base.model.CtaData
|
||||
@@ -40,11 +38,6 @@ object NaviTrackEvent {
|
||||
private lateinit var inAppOptOutScreens: MutableSet<Class<*>>
|
||||
private lateinit var appContext: Application
|
||||
|
||||
val moengageUtil by lazy {
|
||||
MoengageUtil.init(appContext, analyticsConfiguration.moengageData, inAppOptOutScreens)
|
||||
MoengageUtil
|
||||
}
|
||||
|
||||
fun appInit(
|
||||
appContext: Application,
|
||||
analyticsConfiguration: AnalyticsConfiguration,
|
||||
@@ -107,7 +100,6 @@ object NaviTrackEvent {
|
||||
isNeededForFirebase: Boolean = true
|
||||
) {
|
||||
screenName?.apply {
|
||||
moengageUtil.trackScreenName(this, context = applicationContext)
|
||||
if (isNeededForFirebase) FcmAnalyticsUtil.analytics.trackScreenOpen(this)
|
||||
PulseManager.trackEvent(screenName)
|
||||
if (isEventWhiteListedForAppsflyer(this)) {
|
||||
@@ -123,7 +115,6 @@ object NaviTrackEvent {
|
||||
isNeededForFirebase: Boolean = true
|
||||
) {
|
||||
screenName?.apply {
|
||||
moengageUtil.trackEvent(this, eventValues, context = applicationContext)
|
||||
if (isNeededForFirebase) FcmAnalyticsUtil.analytics.trackEvent(this, eventValues)
|
||||
PulseManager.trackEvent(this, eventValues)
|
||||
if (isEventWhiteListedForAppsflyer(this)) {
|
||||
@@ -163,7 +154,6 @@ object NaviTrackEvent {
|
||||
isNeededForAppsflyer: Boolean = false,
|
||||
isNeededForFirebase: Boolean = false
|
||||
) {
|
||||
moengageUtil.trackEvent(eventName, eventValues, applicationContext)
|
||||
if (isNeededForFirebase) FcmAnalyticsUtil.analytics.trackEvent(eventName, eventValues)
|
||||
PulseManager.trackEvent(eventName, eventValues)
|
||||
if (isNeededForAppsflyer || isEventWhiteListedForAppsflyer(eventName)) {
|
||||
@@ -178,7 +168,6 @@ object NaviTrackEvent {
|
||||
}
|
||||
|
||||
fun trackEventOnAllThirdParty(eventName: String, eventValues: Map<String, String>? = null) {
|
||||
moengageUtil.trackEvent(eventName, eventValues, applicationContext)
|
||||
if (isEventWhiteListedForAppsflyer(eventName)) {
|
||||
AppsFlyerUtil.instance.trackEvent(applicationContext, eventName, eventValues)
|
||||
}
|
||||
@@ -186,7 +175,6 @@ object NaviTrackEvent {
|
||||
}
|
||||
|
||||
fun setUserId(id: String) {
|
||||
moengageUtil.setUserId(id, applicationContext)
|
||||
FcmAnalyticsUtil.analytics.setUserId(id)
|
||||
AppsFlyerUtil.instance.setCustomerId(id)
|
||||
PulseManager.setUserId(id)
|
||||
@@ -197,36 +185,7 @@ object NaviTrackEvent {
|
||||
PulseManager.setSessionId(sessionId)
|
||||
}
|
||||
|
||||
fun setUserAttributes(
|
||||
name: String? = null,
|
||||
phoneNumber: String? = null,
|
||||
email: String? = null,
|
||||
maritalStatus: String? = null,
|
||||
pinCode: String? = null,
|
||||
employmentType: String? = null,
|
||||
companyName: String? = null,
|
||||
monthlyIncomeAmount: Double? = null,
|
||||
gender: String? = null
|
||||
) {
|
||||
moengageUtil.setUserAttributes(
|
||||
applicationContext,
|
||||
name,
|
||||
phoneNumber,
|
||||
email,
|
||||
maritalStatus,
|
||||
pinCode,
|
||||
employmentType,
|
||||
companyName,
|
||||
monthlyIncomeAmount,
|
||||
gender
|
||||
)
|
||||
}
|
||||
|
||||
fun setLatLongAttribute(location: UserLocation?) =
|
||||
moengageUtil.setLatLongAttribute(location, applicationContext)
|
||||
|
||||
fun logoutUser() {
|
||||
moengageUtil.logoutUser(applicationContext)
|
||||
PulseManager.setUserId(null)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user