Skip to content

Commit

Permalink
feat: upgraded to the latest version of appsflyer sdk and added suppo…
Browse files Browse the repository at this point in the history
…rt for new events
  • Loading branch information
Desu Sai Venkat committed Apr 12, 2023
1 parent 4969f63 commit f5259f0
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 8 deletions.
5 changes: 3 additions & 2 deletions appsflyer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ android {

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

// rudder core sdk
implementation 'com.rudderstack.android.sdk:core:[1.2.1,)'
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_CLICK;
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_VIEW;
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
4 changes: 2 additions & 2 deletions sample-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 33
defaultConfig {
applicationId "com.rudderstack.test.android"
applicationId "com.rudderstack.test.android3"
minSdkVersion 19
targetSdkVersion 33
versionCode 1
Expand Down Expand Up @@ -43,7 +43,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()
)
}
}

0 comments on commit f5259f0

Please sign in to comment.