From 70c190e07a1808bf4708453fc73c26d80786a682 Mon Sep 17 00:00:00 2001 From: Alexander Zatsepin Date: Mon, 24 Sep 2018 18:25:21 +0300 Subject: [PATCH] [android] Added ads removal statistic --- .../purchase/AdsRemovalPurchaseCallback.java | 3 +- .../AdsRemovalPurchaseController.java | 10 ++- .../purchase/AdsRemovalPurchaseDialog.java | 23 ++++++- .../purchase/PlayStoreBillingCallback.java | 3 +- .../purchase/PlayStoreBillingManager.java | 4 +- .../widget/placepage/BannerController.java | 10 ++- .../util/statistics/Statistics.java | 67 +++++++++++++++++++ 7 files changed, 109 insertions(+), 11 deletions(-) diff --git a/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseCallback.java b/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseCallback.java index 7d70a2ad5f..dfdcc4e22c 100644 --- a/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseCallback.java +++ b/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseCallback.java @@ -2,6 +2,7 @@ package com.mapswithme.maps.purchase; import android.support.annotation.NonNull; +import com.android.billingclient.api.BillingClient; import com.android.billingclient.api.SkuDetails; import java.util.List; @@ -9,7 +10,7 @@ import java.util.List; public interface AdsRemovalPurchaseCallback { void onProductDetailsLoaded(@NonNull List details); - void onPaymentFailure(); + void onPaymentFailure(@BillingClient.BillingResponse int error); void onProductDetailsFailure(); void onValidationStarted(); void onValidationStatusObtained(@NonNull AdsRemovalValidationStatus status); diff --git a/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseController.java b/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseController.java index fb6254f081..fb99ac6ceb 100644 --- a/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseController.java +++ b/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseController.java @@ -5,12 +5,15 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; +import com.android.billingclient.api.BillingClient; import com.android.billingclient.api.Purchase; import com.android.billingclient.api.SkuDetails; import com.mapswithme.maps.Framework; +import com.mapswithme.maps.PrivateVariables; import com.mapswithme.util.ConnectionState; import com.mapswithme.util.log.Logger; import com.mapswithme.util.log.LoggerFactory; +import com.mapswithme.util.statistics.Statistics; import java.util.Arrays; import java.util.Collections; @@ -66,7 +69,8 @@ class AdsRemovalPurchaseController extends AbstractPurchaseController details); void onPurchaseSuccessful(@NonNull List purchases); - void onPurchaseFailure(); + void onPurchaseFailure(@BillingClient.BillingResponse int error); void onPurchaseDetailsFailure(); void onPurchasesLoaded(@NonNull List purchases); } diff --git a/android/src/com/mapswithme/maps/purchase/PlayStoreBillingManager.java b/android/src/com/mapswithme/maps/purchase/PlayStoreBillingManager.java index 6ca1df7d46..5cb5a06ca6 100644 --- a/android/src/com/mapswithme/maps/purchase/PlayStoreBillingManager.java +++ b/android/src/com/mapswithme/maps/purchase/PlayStoreBillingManager.java @@ -143,7 +143,7 @@ class PlayStoreBillingManager implements BillingManager handleAdsRemoval()); + mAdsRemovalButton.setOnClickListener(this::handleAdsRemoval); mAdChoices = mBannerView.findViewById(R.id.ad_choices_icon); mAdChoices.setOnClickListener(v -> handlePrivacyInfoUrl()); mAdChoicesLabel = mBannerView.findViewById(R.id.ad_choices_label); mAdsRemovalIcon = mBannerView.findViewById(R.id.remove_btn); - mAdsRemovalIcon.setOnClickListener(v -> handleAdsRemoval()); + mAdsRemovalIcon.setOnClickListener(this::handleAdsRemoval); Resources res = mBannerView.getResources(); final int tapArea = res.getDimensionPixelSize(R.dimen.margin_quarter_plus); UiUtils.expandTouchAreaForViews(tapArea, mAdChoices, mAdsRemovalIcon); @@ -176,8 +176,12 @@ final class BannerController Utils.openUrl(mBannerView.getContext(), privacyUrl); } - private void handleAdsRemoval() + private void handleAdsRemoval(@NonNull View clickedView) { + boolean isCross = clickedView.getId() == R.id.remove_btn; + @Statistics.BannerState + int state = mOpened ? PP_BANNER_STATE_DETAILS : PP_BANNER_STATE_PREVIEW; + Statistics.INSTANCE.trackPPBannerClose(state, isCross); FragmentActivity activity = (FragmentActivity) mBannerView.getContext(); AdsRemovalPurchaseDialog fragment = (AdsRemovalPurchaseDialog) Fragment.instantiate(activity, AdsRemovalPurchaseDialog.class.getName()); diff --git a/android/src/com/mapswithme/util/statistics/Statistics.java b/android/src/com/mapswithme/util/statistics/Statistics.java index 5ef1dad3dc..efcd8bae1b 100644 --- a/android/src/com/mapswithme/util/statistics/Statistics.java +++ b/android/src/com/mapswithme/util/statistics/Statistics.java @@ -13,6 +13,7 @@ import android.text.TextUtils; import android.util.Log; import android.util.Pair; +import com.android.billingclient.api.BillingClient; import com.facebook.ads.AdError; import com.facebook.appevents.AppEventsLogger; import com.flurry.android.FlurryAgent; @@ -29,6 +30,7 @@ import com.mapswithme.maps.downloader.MapManager; import com.mapswithme.maps.editor.Editor; import com.mapswithme.maps.editor.OsmOAuth; import com.mapswithme.maps.location.LocationHelper; +import com.mapswithme.maps.purchase.AdsRemovalValidationStatus; import com.mapswithme.maps.routing.RoutePointInfo; import com.mapswithme.maps.taxi.TaxiInfoError; import com.mapswithme.maps.taxi.TaxiManager; @@ -64,7 +66,13 @@ import static com.mapswithme.util.statistics.Statistics.EventName.BM_SYNC_PROPOS import static com.mapswithme.util.statistics.Statistics.EventName.BM_SYNC_PROPOSAL_TOGGLE; import static com.mapswithme.util.statistics.Statistics.EventName.BM_SYNC_SUCCESS; import static com.mapswithme.util.statistics.Statistics.EventName.DOWNLOADER_DIALOG_ERROR; +import static com.mapswithme.util.statistics.Statistics.EventName.INAPP_PURCHASE_PREVIEW_SELECT; +import static com.mapswithme.util.statistics.Statistics.EventName.INAPP_PURCHASE_PREVIEW_SHOW; +import static com.mapswithme.util.statistics.Statistics.EventName.INAPP_PURCHASE_PRODUCT_DELIVERED; +import static com.mapswithme.util.statistics.Statistics.EventName.INAPP_PURCHASE_STORE_ERROR; +import static com.mapswithme.util.statistics.Statistics.EventName.INAPP_PURCHASE_VALIDATION_ERROR; import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_BLANK; +import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_CLOSE; import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_ERROR; import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_SHOW; import static com.mapswithme.util.statistics.Statistics.EventName.PP_OWNERSHIP_BUTTON_CLICK; @@ -109,6 +117,7 @@ import static com.mapswithme.util.statistics.Statistics.EventParam.NETWORK; import static com.mapswithme.util.statistics.Statistics.EventParam.OBJECT_LAT; import static com.mapswithme.util.statistics.Statistics.EventParam.OBJECT_LON; import static com.mapswithme.util.statistics.Statistics.EventParam.PLACEMENT; +import static com.mapswithme.util.statistics.Statistics.EventParam.PRODUCT; import static com.mapswithme.util.statistics.Statistics.EventParam.PROVIDER; import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT; import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT_LAT; @@ -116,6 +125,7 @@ import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT_LO import static com.mapswithme.util.statistics.Statistics.EventParam.STATE; import static com.mapswithme.util.statistics.Statistics.EventParam.TYPE; import static com.mapswithme.util.statistics.Statistics.EventParam.VALUE; +import static com.mapswithme.util.statistics.Statistics.EventParam.VENDOR; import static com.mapswithme.util.statistics.Statistics.ParamValue.BACKUP; import static com.mapswithme.util.statistics.Statistics.ParamValue.BICYCLE; import static com.mapswithme.util.statistics.Statistics.ParamValue.BOOKING_COM; @@ -232,6 +242,7 @@ public enum Statistics public static final String PP_BANNER_SHOW = "Placepage_Banner_show"; public static final String PP_BANNER_ERROR = "Placepage_Banner_error"; public static final String PP_BANNER_BLANK = "Placepage_Banner_blank"; + public static final String PP_BANNER_CLOSE = "Placepage_Banner_close"; public static final String PP_HOTEL_GALLERY_OPEN = "PlacePage_Hotel_Gallery_open"; public static final String PP_HOTEL_REVIEWS_LAND = "PlacePage_Hotel_Reviews_land"; public static final String PP_HOTEL_DESCRIPTION_LAND = "PlacePage_Hotel_Description_land"; @@ -317,6 +328,17 @@ public enum Statistics public static final String UGC_AUTH_ERROR = "UGC_Auth_error"; public static final String MAP_LAYERS_ACTIVATE = "Map_Layers_activate"; + // Purchases. + public static final String INAPP_PURCHASE_PREVIEW_SHOW = "InAppPurchase_Preview_show"; + public static final String INAPP_PURCHASE_PREVIEW_SELECT = "InAppPurchase_Preview_select"; + public static final String INAPP_PURCHASE_PREVIEW_PAY = "InAppPurchase_Preview_pay"; + public static final String INAPP_PURCHASE_PREVIEW_CANCEL = "InAppPurchase_Preview_cancel"; + public static final String INAPP_PURCHASE_STORE_SUCCESS = "InAppPurchase_Store_success"; + public static final String INAPP_PURCHASE_STORE_ERROR = "InAppPurchase_Store_error"; + public static final String INAPP_PURCHASE_VALIDATION_SUCCESS = "InAppPurchase_Validation_success"; + public static final String INAPP_PURCHASE_VALIDATION_ERROR = "InAppPurchase_Validation_error"; + public static final String INAPP_PURCHASE_PRODUCT_DELIVERED = "InAppPurchase_Product_delivered"; + public static class Settings { public static final String WEB_SITE = "Setings. Go to website"; @@ -405,6 +427,8 @@ public enum Statistics public static final String STATUS = "status"; static final String INTERRUPTED = "interrupted"; static final String BUTTON = "button"; + static final String VENDOR = "vendor"; + static final String PRODUCT = "product"; private EventParam() {} } @@ -1293,6 +1317,49 @@ public enum Statistics return params().add(BUTTON, button.name().toLowerCase()); } + public void trackPPBannerClose(@BannerState int state, boolean isCross) + { + trackEvent(PP_BANNER_CLOSE, params().add(BANNER, state) + .add(BUTTON, isCross ? 0 : 1)); + } + + public void trackPurchasePreviewShow(@NonNull String vendor, @NonNull String productId) + { + trackEvent(INAPP_PURCHASE_PREVIEW_SHOW, params().add(VENDOR, vendor) + .add(PRODUCT, productId)); + } + + public void trackPurchasePreviewSelect(@NonNull String productId) + { + trackEvent(INAPP_PURCHASE_PREVIEW_SELECT, params().add(PRODUCT, productId)); + } + + public void trackPurchaseStoreError(@BillingClient.BillingResponse int error) + { + trackEvent(INAPP_PURCHASE_STORE_ERROR, params().add(ERROR, "Billing error: " + error)); + } + + public void trackPurchaseValidationError(@NonNull AdsRemovalValidationStatus status) + { + if (status == AdsRemovalValidationStatus.VERIFIED) + return; + + int errorCode; + if (status == AdsRemovalValidationStatus.NOT_VERIFIED) + errorCode = 0; + else if (status == AdsRemovalValidationStatus.SERVER_ERROR) + errorCode = 2; + else + return; + + trackEvent(INAPP_PURCHASE_VALIDATION_ERROR, params().add(ERROR_CODE, errorCode)); + } + + public void trackPurchaseProductDelivered(@NonNull String vendor) + { + trackEvent(INAPP_PURCHASE_PRODUCT_DELIVERED, params().add(VENDOR, vendor)); + } + public static ParameterBuilder params() { return new ParameterBuilder();