앱스플라이어 딥링크
- 가장 먼저 실행되는 Application 영역으로 이동
This commit is contained in:
		@@ -4,9 +4,13 @@ import android.app.Application
 | 
			
		||||
import android.content.pm.ApplicationInfo
 | 
			
		||||
import android.content.pm.PackageManager
 | 
			
		||||
import android.os.Build
 | 
			
		||||
import android.os.Bundle
 | 
			
		||||
import androidx.appcompat.app.AppCompatDelegate
 | 
			
		||||
import com.appsflyer.AppsFlyerLib
 | 
			
		||||
import com.appsflyer.deeplink.DeepLinkResult
 | 
			
		||||
import com.facebook.FacebookSdk
 | 
			
		||||
import com.google.firebase.analytics.ktx.analytics
 | 
			
		||||
import com.google.firebase.ktx.Firebase
 | 
			
		||||
import com.orhanobut.logger.AndroidLogAdapter
 | 
			
		||||
import com.orhanobut.logger.Logger
 | 
			
		||||
import kr.co.vividnext.sodalive.BuildConfig
 | 
			
		||||
@@ -61,5 +65,54 @@ class SodaLiveApp : Application() {
 | 
			
		||||
        // Appsflyer SDK 초기화
 | 
			
		||||
        AppsFlyerLib.getInstance().init("tWF2wbJ5nSkya5Ru9mGcPU", null, this)
 | 
			
		||||
        AppsFlyerLib.getInstance().start(this)
 | 
			
		||||
 | 
			
		||||
        // 딥링크 및 디퍼드 딥링크 처리
 | 
			
		||||
        AppsFlyerLib.getInstance().subscribeForDeepLink { deepLinkResult ->
 | 
			
		||||
            when (deepLinkResult.status) {
 | 
			
		||||
                DeepLinkResult.Status.FOUND -> {
 | 
			
		||||
                    val deepLink = deepLinkResult.deepLink
 | 
			
		||||
                    SharedPreferenceManager.marketingLinkValue = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_value"
 | 
			
		||||
                    ) ?: ""
 | 
			
		||||
 | 
			
		||||
                    val marketingPid = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_sub1"
 | 
			
		||||
                    )
 | 
			
		||||
 | 
			
		||||
                    if (marketingPid != null) {
 | 
			
		||||
                        SharedPreferenceManager.marketingPid = marketingPid
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    SharedPreferenceManager.marketingUtmSource = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_sub2"
 | 
			
		||||
                    ) ?: ""
 | 
			
		||||
                    SharedPreferenceManager.marketingUtmMedium = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_sub3"
 | 
			
		||||
                    ) ?: ""
 | 
			
		||||
                    SharedPreferenceManager.marketingUtmCampaign = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_sub4"
 | 
			
		||||
                    ) ?: ""
 | 
			
		||||
                    SharedPreferenceManager.marketingLinkValueId = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_sub5"
 | 
			
		||||
                    )?.toLongOrNull() ?: 0L
 | 
			
		||||
 | 
			
		||||
                    logUtmInFirebase()
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                DeepLinkResult.Status.NOT_FOUND -> Logger.d("딥링크를 찾을 수 없습니다.")
 | 
			
		||||
                DeepLinkResult.Status.ERROR -> Logger.d("딥링크 처리 중 오류 발생: ${deepLinkResult.error}")
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun logUtmInFirebase() {
 | 
			
		||||
        val firebaseAnalytics = Firebase.analytics
 | 
			
		||||
        val params = Bundle().apply {
 | 
			
		||||
            putString("utm_source", SharedPreferenceManager.marketingUtmSource)
 | 
			
		||||
            putString("utm_medium", SharedPreferenceManager.marketingUtmMedium)
 | 
			
		||||
            putString("utm_campaign", SharedPreferenceManager.marketingUtmCampaign)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        firebaseAnalytics.logEvent("campaign_utm", params)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,56 +5,12 @@ import android.os.Bundle
 | 
			
		||||
import android.os.Handler
 | 
			
		||||
import android.os.Looper
 | 
			
		||||
import androidx.appcompat.app.AppCompatActivity
 | 
			
		||||
import com.appsflyer.AppsFlyerLib
 | 
			
		||||
import com.appsflyer.deeplink.DeepLinkResult
 | 
			
		||||
import com.google.firebase.analytics.ktx.analytics
 | 
			
		||||
import com.google.firebase.ktx.Firebase
 | 
			
		||||
import com.orhanobut.logger.Logger
 | 
			
		||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
 | 
			
		||||
import kr.co.vividnext.sodalive.splash.SplashActivity
 | 
			
		||||
 | 
			
		||||
class DeepLinkActivity : AppCompatActivity() {
 | 
			
		||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
			
		||||
        super.onCreate(savedInstanceState)
 | 
			
		||||
 | 
			
		||||
        // 딥링크 및 디퍼드 딥링크 처리
 | 
			
		||||
        AppsFlyerLib.getInstance().subscribeForDeepLink { deepLinkResult ->
 | 
			
		||||
            when (deepLinkResult.status) {
 | 
			
		||||
                DeepLinkResult.Status.FOUND -> {
 | 
			
		||||
                    val deepLink = deepLinkResult.deepLink
 | 
			
		||||
                    SharedPreferenceManager.marketingLinkValue = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_value"
 | 
			
		||||
                    ) ?: ""
 | 
			
		||||
 | 
			
		||||
                    val marketingPid = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_sub1"
 | 
			
		||||
                    )
 | 
			
		||||
 | 
			
		||||
                    if (marketingPid != null) {
 | 
			
		||||
                        SharedPreferenceManager.marketingPid = marketingPid
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    SharedPreferenceManager.marketingUtmSource = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_sub2"
 | 
			
		||||
                    ) ?: ""
 | 
			
		||||
                    SharedPreferenceManager.marketingUtmMedium = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_sub3"
 | 
			
		||||
                    ) ?: ""
 | 
			
		||||
                    SharedPreferenceManager.marketingUtmCampaign = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_sub4"
 | 
			
		||||
                    ) ?: ""
 | 
			
		||||
                    SharedPreferenceManager.marketingLinkValueId = deepLink?.getStringValue(
 | 
			
		||||
                        "deep_link_sub5"
 | 
			
		||||
                    )?.toLongOrNull() ?: 0L
 | 
			
		||||
 | 
			
		||||
                    logUtmInFirebase()
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                DeepLinkResult.Status.NOT_FOUND -> Logger.d("딥링크를 찾을 수 없습니다.")
 | 
			
		||||
                DeepLinkResult.Status.ERROR -> Logger.d("딥링크 처리 중 오류 발생: ${deepLinkResult.error}")
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        startActivity(
 | 
			
		||||
            Intent(applicationContext, SplashActivity::class.java).apply {
 | 
			
		||||
                data = intent.data
 | 
			
		||||
@@ -65,15 +21,4 @@ class DeepLinkActivity : AppCompatActivity() {
 | 
			
		||||
            finish()
 | 
			
		||||
        }, 1000)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun logUtmInFirebase() {
 | 
			
		||||
        val firebaseAnalytics = Firebase.analytics
 | 
			
		||||
        val params = Bundle().apply {
 | 
			
		||||
            putString("utm_source", SharedPreferenceManager.marketingUtmSource)
 | 
			
		||||
            putString("utm_medium", SharedPreferenceManager.marketingUtmMedium)
 | 
			
		||||
            putString("utm_campaign", SharedPreferenceManager.marketingUtmCampaign)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        firebaseAnalytics.logEvent("campaign_utm", params)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user