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

feat: upgraded to the latest version of appsflyer sdk and added mapping for new events #14

Closed
wants to merge 4 commits into from
Closed
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
5 changes: 3 additions & 2 deletions appsflyer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// rudder core sdk
implementation 'com.rudderstack.android.sdk:core:[1.8.0,)'
compileOnly 'com.rudderstack.android.sdk:core:[1.12, 2.0)'

// appsflyer dependencies
implementation 'com.appsflyer:af-android-sdk:6.9.4'
implementation 'com.appsflyer:af-android-sdk:[6.10.1, 7.0)'
implementation 'com.android.installreferrer:installreferrer:2.2'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand All @@ -27,8 +28,13 @@
public class AppsFlyerIntegrationFactory extends RudderIntegration<AppsFlyerLib> {
private static final String APPSFLYER_KEY = "AppsFlyer";
private static final String FIRST_PURCHASE = "first_purchase";
public static final String CREATIVE = "creative";
private Boolean isNewScreenEnabled = false;

static final List<String> TRACK_RESERVED_KEYWORDS = Arrays.asList(ECommerceParamNames.QUERY, ECommerceParamNames.PRICE, ECommerceParamNames.PRODUCT_ID, ECommerceParamNames.CATEGORY,
ECommerceParamNames.CURRENCY, ECommerceParamNames.PRODUCTS, ECommerceParamNames.QUANTITY, ECommerceParamNames.TOTAL,
ECommerceParamNames.REVENUE, ECommerceParamNames.ORDER_ID, ECommerceParamNames.SHARE_MESSAGE, CREATIVE, ECommerceParamNames.RATING);

public static RudderIntegration.Factory FACTORY = new Factory() {
@Override
public RudderIntegration<?> create(Object settings, RudderClient client, RudderConfig config) {
Expand All @@ -52,7 +58,7 @@ private AppsFlyerIntegrationFactory(Object config, RudderConfig rudderConfig) {

private void processEvents(RudderMessage message) {
String eventType = message.getType();
String afEventName;
String afEventName = null;
Map<String, Object> afEventProps = new HashMap<>();
if (eventType != null) {
switch (eventType) {
Expand All @@ -64,7 +70,7 @@ private void processEvents(RudderMessage message) {
switch (eventName) {
case ECommerceEvents.PRODUCTS_SEARCHED:
if (property.containsKey(ECommerceParamNames.QUERY)) {
afEventProps.put(AFInAppEventParameterName.SEARCH_STRING, property.get("query"));
afEventProps.put(AFInAppEventParameterName.SEARCH_STRING, property.get(ECommerceParamNames.QUERY));
}
afEventName = AFInAppEventType.SEARCH;
break;
Expand Down Expand Up @@ -100,7 +106,7 @@ private void processEvents(RudderMessage message) {
afEventProps.put(AFInAppEventParameterName.CONTENT_LIST, products.toArray());
}
}
afEventName = "af_list_view";
afEventName = AFInAppEventType.LIST_VIEW;
break;
case ECommerceEvents.PRODUCT_ADDED_TO_WISH_LIST:
if (property.containsKey(ECommerceParamNames.PRICE))
Expand Down Expand Up @@ -141,7 +147,7 @@ private void processEvents(RudderMessage message) {
afEventName = AFInAppEventType.PURCHASE;
break;
case FIRST_PURCHASE:
makeOrderCompletedEvent(property,afEventProps);
makeOrderCompletedEvent(property, afEventProps);
afEventName = FIRST_PURCHASE;
break;
case ECommerceEvents.PRODUCT_REMOVED:
Expand All @@ -151,12 +157,43 @@ private void processEvents(RudderMessage message) {
afEventProps.put(AFInAppEventParameterName.CONTENT_TYPE, property.get(ECommerceParamNames.CATEGORY));
afEventName = "remove_from_cart";
break;
case ECommerceEvents.PROMOTION_VIEWED:
if (property.containsKey(CREATIVE))
afEventProps.put(AFInAppEventParameterName.AD_REVENUE_AD_TYPE, property.get(CREATIVE));
if (property.containsKey(ECommerceParamNames.CURRENCY))
afEventProps.put(AFInAppEventParameterName.CURRENCY, property.get(ECommerceParamNames.CURRENCY));
afEventName = AFInAppEventType.AD_VIEW;
break;
case ECommerceEvents.PROMOTION_CLICKED:
if (property.containsKey(CREATIVE))
afEventProps.put(AFInAppEventParameterName.AD_REVENUE_AD_TYPE, property.get(CREATIVE));
if (property.containsKey(ECommerceParamNames.CURRENCY))
afEventProps.put(AFInAppEventParameterName.CURRENCY, property.get(ECommerceParamNames.CURRENCY));
afEventName = AFInAppEventType.AD_CLICK;
break;
case ECommerceEvents.PAYMENT_INFO_ENTERED:
afEventName = AFInAppEventType.ADD_PAYMENT_INFO;
break;
case ECommerceEvents.PRODUCT_SHARED:
case ECommerceEvents.CART_SHARED:
if (property.containsKey(ECommerceParamNames.SHARE_MESSAGE))
afEventProps.put(AFInAppEventParameterName.DESCRIPTION, property.get(ECommerceParamNames.SHARE_MESSAGE));
afEventName = AFInAppEventType.SHARE;
break;
case ECommerceEvents.PRODUCT_REVIEWED:
if (property.containsKey(ECommerceParamNames.PRODUCT_ID))
afEventProps.put(AFInAppEventParameterName.CONTENT_ID, property.get(ECommerceParamNames.PRODUCT_ID));
if (property.containsKey(ECommerceParamNames.RATING))
afEventProps.put(AFInAppEventParameterName.RATING_VALUE, property.get(ECommerceParamNames.RATING));
afEventName = AFInAppEventType.RATE;
break;
default:
afEventName = eventName.toLowerCase().replace(" ", "_");
}
} else {
afEventName = eventName.toLowerCase().replace(" ", "_");
}
attachAllCustomProperties(afEventProps, property);
AppsFlyerLib.getInstance().logEvent(RudderClient.getApplication(), afEventName, afEventProps);
}
break;
Expand Down Expand Up @@ -191,6 +228,19 @@ private void processEvents(RudderMessage message) {
}
}

private void attachAllCustomProperties(Map<String, Object> afEventProps, Map<String, Object> properties) {
if (properties == null || properties.size() == 0) {
return;
}
for (String key : properties.keySet()) {
Object value = properties.get(key);
if (TRACK_RESERVED_KEYWORDS.contains(key) || TextUtils.isEmpty(key)) {
continue;
}
afEventProps.put(key, value);
}
}

private void makeOrderCompletedEvent(Map<String, Object> eventProperties, Map<String, Object> afEventProps) {
if (eventProperties.containsKey(ECommerceParamNames.TOTAL))
afEventProps.put(AFInAppEventParameterName.PRICE, eventProperties.get(ECommerceParamNames.TOTAL));
Expand Down
1 change: 1 addition & 0 deletions sample-kotlin/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
local.properties
13 changes: 11 additions & 2 deletions sample-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

Properties properties = new Properties()
File localPropertiesFile = new File(project.projectDir, "local.properties")
if (localPropertiesFile.exists()) {
properties.load(localPropertiesFile.newDataInputStream())
}

android {
compileSdkVersion 33
defaultConfig {
applicationId "com.rudderstack.test.android"
applicationId "com.desu.venkat.android"
minSdkVersion 19
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "DATA_PLANE_URL", properties.getProperty('dataplaneUrl', '\"https://hosted.rudderlabs.com\"'))
buildConfigField("String", "CONTROL_PLANE_URL", properties.getProperty('controlplaneUrl', '\"https://api.rudderstack.com\"'))
buildConfigField("String", "WRITE_KEY", properties.getProperty('writeKey', '\"\"'))
}
buildTypes {
release {
Expand All @@ -43,7 +52,7 @@ dependencies {

implementation 'com.rudderstack.android.sdk:core:1.+'
implementation project(':appsflyer')
implementation 'com.appsflyer:af-android-sdk:6.2.0'
implementation 'com.appsflyer:af-android-sdk:6.10.2'
implementation 'com.android.installreferrer:installreferrer:2.2'
implementation 'com.google.code.gson:gson:2.8.6'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,44 @@ class MainActivity : AppCompatActivity() {
productSharedEvent.event(),
productSharedEvent.properties()
)


val cartSharedEvent = CartSharedEvent()
.withCart(cart)
.withSocialChannel("facebook")
.withShareMessage("some message")
.withRecipient("friend@gmail.com")
MainApplication.rudderClient.track(
cartSharedEvent.event(),
cartSharedEvent.properties()
);

val promotionViewedEvent = PromotionViewedEvent()
.withPromotion(
ECommercePromotion(
"firstPromotion",
"mail",
"launch",
"head"
)
);
MainApplication.rudderClient.track(
promotionViewedEvent.event(),
promotionViewedEvent.properties()
)

val promotionClickedEvent = PromotionClickedEvent()
.withPromotion(
ECommercePromotion(
"firstPromotion",
"mail",
"launch",
"head"
)
)
MainApplication.rudderClient.track(
promotionClickedEvent.event(),
promotionClickedEvent.properties()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class MainApplication : Application() {
AppsFlyerLib.getInstance().start(this);
rudderClient = RudderClient.getInstance(
this,
WRITE_KEY,
BuildConfig.WRITE_KEY,
RudderConfig.Builder()
.withDataPlaneUrl(DATA_PLANE_URL)
.withDataPlaneUrl(BuildConfig.DATA_PLANE_URL)
.withFactory(AppsFlyerIntegrationFactory.FACTORY)
.withLogLevel(RudderLogger.RudderLogLevel.DEBUG)
.build()
Expand Down
Loading