Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to Adobe Edge Network (sending inapp event to AF) #4

Open
wants to merge 8 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions adobeextension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,34 @@ android {

dependencies {
api "com.appsflyer:af-android-sdk:$AF_SDK_VERSION"
compileOnly 'com.adobe.marketing.mobile:core:2.+'
compileOnly 'com.adobe.marketing.mobile:identity:2.+'
compileOnly 'com.adobe.marketing.mobile:analytics:2.+'
testImplementation 'com.adobe.marketing.mobile:core:2.+'
testImplementation 'com.adobe.marketing.mobile:identity:2.+'
testImplementation 'com.adobe.marketing.mobile:analytics:2.+'
testImplementation "io.mockk:mockk:1.13.2"
testImplementation 'androidx.test.ext:junit:1.1.5'
testImplementation 'androidx.test:core:1.4.0'
compileOnly platform('com.adobe.marketing.mobile:sdk-bom:3.+')

compileOnly 'com.adobe.marketing.mobile:core'
compileOnly 'com.adobe.marketing.mobile:identity'
compileOnly 'com.adobe.marketing.mobile:analytics'

compileOnly 'com.adobe.marketing.mobile:edge'
compileOnly 'com.adobe.marketing.mobile:edgeidentity'
compileOnly 'com.adobe.marketing.mobile:edgeconsent'

testImplementation platform('com.adobe.marketing.mobile:sdk-bom:3.+')
testImplementation 'com.adobe.marketing.mobile:core'
testImplementation 'com.adobe.marketing.mobile:identity'
testImplementation 'com.adobe.marketing.mobile:analytics'

testImplementation 'junit:junit:4.13.2'
testImplementation "io.mockk:mockk:1.13.2"
testImplementation 'org.mockito:mockito-core:4.2.0'
testImplementation 'org.robolectric:robolectric:4.9.2'

testImplementation 'androidx.test:core:1.4.0'
testImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

testImplementation 'com.android.installreferrer:installreferrer:2.1'
testImplementation 'com.segment.analytics.android:analytics:4.+'
testImplementation 'org.mockito:mockito-core:4.2.0'
testImplementation 'com.segment.analytics.android:analytics-tests:4.+'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply from: file('gradle-mvn-push.gradle')
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
package com.appsflyer.adobeextension

import com.adobe.marketing.mobile.Edge
import com.adobe.marketing.mobile.ExperienceEvent
import com.adobe.marketing.mobile.ExtensionApi
import com.adobe.marketing.mobile.MobileCore
import com.appsflyer.AppsFlyerConversionListener
import com.appsflyer.AppsFlyerLib
import com.appsflyer.adobeextension.AppsflyerAdobeConstants.APPSFLYER_ATTRIBUTION_DATA
import com.appsflyer.adobeextension.AppsflyerAdobeConstants.APPSFLYER_ENGAGMENT_DATA
import com.appsflyer.adobeextension.AppsflyerAdobeExtensionLogger.logAFExtension

typealias TrackGetter = () -> Boolean
typealias ECIDGetter = () -> String?

const val ADOBE_ACTION_KEY = "action"

class AppsflyerAdobeExtensionConversionListener(
private val extensionApi: ExtensionApi,
private val trackAttributionDataGetter: TrackGetter,
private val ecidGetter: ECIDGetter
) : AppsFlyerConversionListener {

override fun onConversionDataSuccess(conversionData: MutableMap<String, Any>) {
logAFExtension("called onConversionDataSuccess")

if (trackAttributionDataGetter()) {
val isFirstLaunch = conversionData[AppsflyerAdobeConstants.IS_FIRST_LAUNCH] as Boolean
if (isFirstLaunch) {
extensionApi.createSharedState(getSharedEventState(conversionData), null)

ContextProvider.context?.let { context ->
AppsFlyerLib.getInstance().getAppsFlyerUID(context)?.let { appsflyerUID ->
conversionData[AppsflyerAdobeConstants.APPSFLYER_ID] = appsflyerUID
}
}
// Send AppsFlyer Attribution data to Adobe Analytics;
ecidGetter()?.let {
conversionData["ecid"] = it
}
MobileCore.trackAction(
AppsflyerAdobeConstants.APPSFLYER_ATTRIBUTION_DATA,
conversionData.setKeyPrefixToAppsflyerDot()
)
ecidGetter()?.let { conversionData["ecid"] = it }
val attributionData = conversionData.setKeyPrefixToAppsflyerDot()

sendDataToAdobe(APPSFLYER_ATTRIBUTION_DATA, attributionData)

} else {
logAFExtension("Skipping attribution data reporting, not first launch")
}
Expand All @@ -47,13 +53,12 @@ class AppsflyerAdobeExtensionConversionListener(

override fun onAppOpenAttribution(deepLinkData: MutableMap<String, String>) {
logAFExtension("called onAppOpenAttribution")
ecidGetter()?.let {
deepLinkData["ecid"] = it
}
MobileCore.trackAction(
AppsflyerAdobeConstants.APPSFLYER_ENGAGMENT_DATA,
deepLinkData.setKeyPrefixOnAppOpenAttribution()
)

ecidGetter()?.let { deepLinkData["ecid"] = it }
val data = deepLinkData.setKeyPrefixOnAppOpenAttribution()

sendDataToAdobe(APPSFLYER_ENGAGMENT_DATA, data)

AppsflyerAdobeExtension.afCallbackListener?.onAppOpenAttribution(deepLinkData)
}

Expand All @@ -78,4 +83,23 @@ class AppsflyerAdobeExtensionConversionListener(
sharedEventState.remove(AppsflyerAdobeConstants.IS_FIRST_LAUNCH)
return sharedEventState
}
}

private fun sendDataToAdobe(action: String, data: Map<String, String?>) {
sendAdobeAnalyticsAction(action, data)
sendAdobeEdgeEvent(action, data)
}

private fun sendAdobeAnalyticsAction(action: String, data: Map<String, String?>) {
MobileCore.trackAction(action, data)
}

private fun sendAdobeEdgeEvent(action: String, data: Map<String, String?>) {
Edge.sendEvent(
ExperienceEvent.Builder().apply {
setData(mapOf(ADOBE_ACTION_KEY to action))
setXdmSchema(data)
}.build(),
null
)
}
}
Loading