forked from organicmaps/organicmaps
[android] Added paid routes statistics
[android] Added purchase id parameter to ads removal and paid routes statistic
This commit is contained in:
parent
7238ff26f9
commit
0b3644d491
9 changed files with 118 additions and 29 deletions
|
@ -123,6 +123,7 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment
|
|||
{
|
||||
mFailedPurchaseController = PurchaseFactory.createFailedBookmarkPurchaseController();
|
||||
mFailedPurchaseController.initialize(getActivity());
|
||||
mFailedPurchaseController.validateExistingPurchases();
|
||||
mPurchaseChecker = new FailedBookmarkPurchaseChecker();
|
||||
View root = inflater.inflate(R.layout.fragment_bookmarks_catalog, container, false);
|
||||
mWebView = root.findViewById(getWebViewResId());
|
||||
|
@ -130,7 +131,6 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment
|
|||
mProgressView = root.findViewById(R.id.progress);
|
||||
initWebView(mWebView);
|
||||
mRetryBtn.setOnClickListener(v -> onRetryClick());
|
||||
mFailedPurchaseController.validateExistingPurchases();
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.support.annotation.IntDef;
|
|||
import android.support.annotation.MainThread;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.PrivateVariables;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
|
@ -258,6 +259,8 @@ public enum BookmarkManager
|
|||
@MainThread
|
||||
public void onImportFinished(@NonNull String id, long catId, boolean successful)
|
||||
{
|
||||
if (successful)
|
||||
Statistics.INSTANCE.trackPurchaseProductDelivered(id, PrivateVariables.bookmarksVendor());
|
||||
for (BookmarksCatalogListener listener : mCatalogListeners)
|
||||
listener.onImportFinished(id, catId, successful);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,8 @@ enum AdsRemovalPaymentState
|
|||
View image = view.findViewById(R.id.image);
|
||||
alignPayButtonBelow(view, image == null ? R.id.title : R.id.image);
|
||||
dialog.updatePaymentButtons();
|
||||
Statistics.INSTANCE.trackPurchasePreviewShow(PrivateVariables.adsRemovalVendor(),
|
||||
Statistics.INSTANCE.trackPurchasePreviewShow(PrivateVariables.adsRemovalServerId(),
|
||||
PrivateVariables.adsRemovalVendor(),
|
||||
PrivateVariables.adsRemovalYearlyProductId());
|
||||
}
|
||||
},
|
||||
|
|
|
@ -52,16 +52,18 @@ class AdsRemovalPurchaseController extends AbstractPurchaseController<Validation
|
|||
{
|
||||
LOGGER.i(TAG, "Validation status of 'ads removal': " + status);
|
||||
if (status == ValidationStatus.VERIFIED)
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.INAPP_PURCHASE_VALIDATION_SUCCESS);
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_VALIDATION_SUCCESS,
|
||||
PrivateVariables.adsRemovalServerId());
|
||||
else
|
||||
Statistics.INSTANCE.trackPurchaseValidationError(status);
|
||||
Statistics.INSTANCE.trackPurchaseValidationError(PrivateVariables.adsRemovalServerId(), status);
|
||||
|
||||
final boolean activateSubscription = status != ValidationStatus.NOT_VERIFIED;
|
||||
final boolean hasActiveSubscription = Framework.nativeHasActiveRemoveAdsSubscription();
|
||||
if (!hasActiveSubscription && activateSubscription)
|
||||
{
|
||||
LOGGER.i(TAG, "Ads removal subscription activated");
|
||||
Statistics.INSTANCE.trackPurchaseProductDelivered(PrivateVariables.adsRemovalVendor());
|
||||
Statistics.INSTANCE.trackPurchaseProductDelivered(PrivateVariables.adsRemovalServerId(),
|
||||
PrivateVariables.adsRemovalVendor());
|
||||
}
|
||||
else if (hasActiveSubscription && !activateSubscription)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.android.billingclient.api.BillingClient;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
import com.mapswithme.maps.PrivateVariables;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.maps.dialog.AlertDialogCallback;
|
||||
|
@ -184,8 +185,11 @@ public class AdsRemovalPurchaseDialog extends BaseMwmDialogFragment
|
|||
{
|
||||
ProductDetails details = getProductDetailsForPeriod(period);
|
||||
getControllerOrThrow().launchPurchaseFlow(details.getProductId());
|
||||
Statistics.INSTANCE.trackPurchasePreviewSelect(details.getProductId());
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.INAPP_PURCHASE_PREVIEW_PAY);
|
||||
String purchaseId = PrivateVariables.adsRemovalServerId();
|
||||
Statistics.INSTANCE.trackPurchasePreviewSelect(PrivateVariables.adsRemovalServerId(),
|
||||
details.getProductId());
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_PREVIEW_PAY,
|
||||
purchaseId);
|
||||
}
|
||||
|
||||
void onExplanationClick()
|
||||
|
@ -232,7 +236,8 @@ public class AdsRemovalPurchaseDialog extends BaseMwmDialogFragment
|
|||
public void onCancel(DialogInterface dialog)
|
||||
{
|
||||
super.onCancel(dialog);
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.INAPP_PURCHASE_PREVIEW_CANCEL);
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_PREVIEW_CANCEL,
|
||||
PrivateVariables.adsRemovalServerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -378,7 +383,7 @@ public class AdsRemovalPurchaseDialog extends BaseMwmDialogFragment
|
|||
@Override
|
||||
public void onPaymentFailure(@BillingClient.BillingResponse int error)
|
||||
{
|
||||
Statistics.INSTANCE.trackPurchaseStoreError(error);
|
||||
Statistics.INSTANCE.trackPurchaseStoreError(PrivateVariables.adsRemovalServerId(), error);
|
||||
activateStateSafely(AdsRemovalPaymentState.PAYMENT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -397,7 +402,8 @@ public class AdsRemovalPurchaseDialog extends BaseMwmDialogFragment
|
|||
@Override
|
||||
public void onValidationStarted()
|
||||
{
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.INAPP_PURCHASE_STORE_SUCCESS);
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_STORE_SUCCESS,
|
||||
PrivateVariables.adsRemovalServerId());
|
||||
activateStateSafely(AdsRemovalPaymentState.VALIDATION);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,9 @@ import android.support.annotation.NonNull;
|
|||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
import com.mapswithme.maps.bookmarks.data.PaymentData;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
public class BookmarkPaymentActivity extends BaseMwmFragmentActivity
|
||||
{
|
||||
|
@ -25,4 +27,10 @@ public class BookmarkPaymentActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
return BookmarkPaymentFragment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onBackPressedInternal(@NonNull Fragment currentFragment)
|
||||
{
|
||||
return Utils.<OnBackPressListener>castTo(currentFragment).onBackPressed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.billingclient.api.BillingClient;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.mapswithme.maps.Framework;
|
||||
|
@ -23,6 +24,7 @@ import com.mapswithme.maps.dialog.AlertDialogCallback;
|
|||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -43,8 +45,9 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private PurchaseController<PurchaseCallback> mPurchaseController;
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private BookmarkPurchaseCallback mPurchaseCallback = new BookmarkPurchaseCallback();
|
||||
private BookmarkPurchaseCallback mPurchaseCallback;
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private PaymentData mPaymentData;
|
||||
|
@ -67,6 +70,7 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
throw new IllegalStateException("Payment data must be provided for payment fragment!");
|
||||
|
||||
mPaymentData = paymentData;
|
||||
mPurchaseCallback = new BookmarkPurchaseCallback(mPaymentData.getServerId());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -79,16 +83,44 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
mPurchaseController.initialize(getActivity());
|
||||
View root = inflater.inflate(R.layout.fragment_bookmark_payment, container, false);
|
||||
TextView buyButton = root.findViewById(R.id.buy_btn);
|
||||
buyButton.setOnClickListener(v -> startPurchaseTransaction());
|
||||
buyButton.setOnClickListener(v -> onBuyClicked());
|
||||
TextView cancelButton = root.findViewById(R.id.cancel_btn);
|
||||
cancelButton.setOnClickListener(v -> getActivity().finish());
|
||||
cancelButton.setOnClickListener(v -> onCancelClicked());
|
||||
return root;
|
||||
}
|
||||
|
||||
private void onBuyClicked()
|
||||
{
|
||||
Statistics.INSTANCE.trackPurchasePreviewSelect(mPaymentData.getServerId(),
|
||||
mPaymentData.getProductId());
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_PREVIEW_PAY,
|
||||
mPaymentData.getServerId());
|
||||
startPurchaseTransaction();
|
||||
}
|
||||
|
||||
private void onCancelClicked()
|
||||
{
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_PREVIEW_CANCEL,
|
||||
mPaymentData.getServerId());
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed()
|
||||
{
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_PREVIEW_CANCEL,
|
||||
mPaymentData.getServerId());
|
||||
return super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
if (savedInstanceState == null)
|
||||
Statistics.INSTANCE.trackPurchasePreviewShow(mPaymentData.getServerId(),
|
||||
PrivateVariables.bookmarksVendor(),
|
||||
mPaymentData.getProductId());
|
||||
LOGGER.d(TAG, "onViewCreated savedInstanceState = " + savedInstanceState);
|
||||
setInitialPaymentData();
|
||||
loadImage();
|
||||
|
@ -257,6 +289,13 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
@Nullable
|
||||
private List<SkuDetails> mPendingDetails;
|
||||
private Boolean mPendingValidationResult;
|
||||
@NonNull
|
||||
private final String mServerId;
|
||||
|
||||
private BookmarkPurchaseCallback(@NonNull String serverId)
|
||||
{
|
||||
mServerId = serverId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTransaction(boolean success, @NonNull String serverId, @NonNull String
|
||||
|
@ -284,7 +323,7 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPaymentFailure(int error)
|
||||
public void onPaymentFailure(@BillingClient.BillingResponse int error)
|
||||
{
|
||||
activateStateSafely(BookmarkPaymentState.PAYMENT_FAILURE);
|
||||
}
|
||||
|
@ -304,6 +343,8 @@ public class BookmarkPaymentFragment extends BaseMwmFragment
|
|||
@Override
|
||||
public void onValidationStarted()
|
||||
{
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_STORE_SUCCESS,
|
||||
mServerId);
|
||||
activateStateSafely(BookmarkPaymentState.VALIDATION);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ 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.List;
|
||||
|
||||
|
@ -56,11 +57,16 @@ class BookmarkPurchaseController extends AbstractPurchaseController<ValidationCa
|
|||
LOGGER.i(TAG, "Validation status of 'paid bookmark': " + status);
|
||||
if (status == ValidationStatus.VERIFIED)
|
||||
{
|
||||
//noinspection ConstantConditions
|
||||
Statistics.INSTANCE.trackPurchaseEvent(Statistics.EventName.INAPP_PURCHASE_VALIDATION_SUCCESS,
|
||||
mServerId);
|
||||
LOGGER.i(TAG, "Bookmark purchase consuming...");
|
||||
getBillingManager().consumePurchase(PurchaseUtils.parseToken(purchaseData));
|
||||
return;
|
||||
}
|
||||
|
||||
//noinspection ConstantConditions
|
||||
Statistics.INSTANCE.trackPurchaseValidationError(mServerId, status);
|
||||
if (getUiCallback() != null)
|
||||
getUiCallback().onValidationFinish(false);
|
||||
}
|
||||
|
@ -68,6 +74,14 @@ class BookmarkPurchaseController extends AbstractPurchaseController<ValidationCa
|
|||
|
||||
private class PlayStoreBillingCallbackImpl extends AbstractPlayStoreBillingCallback
|
||||
{
|
||||
@Override
|
||||
public void onPurchaseFailure(int error)
|
||||
{
|
||||
super.onPurchaseFailure(error);
|
||||
//noinspection ConstantConditions
|
||||
Statistics.INSTANCE.trackPurchaseStoreError(mServerId, error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseDetailsLoaded(@NonNull List<SkuDetails> details)
|
||||
{
|
||||
|
|
|
@ -118,6 +118,7 @@ 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.PURCHASE;
|
||||
import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT;
|
||||
import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT_LAT;
|
||||
import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT_LON;
|
||||
|
@ -328,15 +329,15 @@ public enum Statistics
|
|||
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";
|
||||
static final String INAPP_PURCHASE_PREVIEW_SHOW = "InAppPurchase_Preview_show";
|
||||
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";
|
||||
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";
|
||||
static final String INAPP_PURCHASE_VALIDATION_ERROR = "InAppPurchase_Validation_error";
|
||||
static final String INAPP_PURCHASE_PRODUCT_DELIVERED = "InAppPurchase_Product_delivered";
|
||||
|
||||
public static class Settings
|
||||
{
|
||||
|
@ -428,6 +429,7 @@ public enum Statistics
|
|||
static final String BUTTON = "button";
|
||||
static final String VENDOR = "vendor";
|
||||
static final String PRODUCT = "product";
|
||||
static final String PURCHASE = "purchase";
|
||||
|
||||
private EventParam() {}
|
||||
}
|
||||
|
@ -1315,23 +1317,33 @@ public enum Statistics
|
|||
.add(BUTTON, isCross ? 0 : 1));
|
||||
}
|
||||
|
||||
public void trackPurchasePreviewShow(@NonNull String vendor, @NonNull String productId)
|
||||
public void trackPurchasePreviewShow(@NonNull String purchaseId, @NonNull String vendor,
|
||||
@NonNull String productId)
|
||||
{
|
||||
trackEvent(INAPP_PURCHASE_PREVIEW_SHOW, params().add(VENDOR, vendor)
|
||||
.add(PRODUCT, productId));
|
||||
.add(PRODUCT, productId)
|
||||
.add(PURCHASE, purchaseId));
|
||||
}
|
||||
|
||||
public void trackPurchasePreviewSelect(@NonNull String productId)
|
||||
public void trackPurchaseEvent(@NonNull String event, @NonNull String purchaseId)
|
||||
{
|
||||
trackEvent(INAPP_PURCHASE_PREVIEW_SELECT, params().add(PRODUCT, productId));
|
||||
trackEvent(event, params().add(PURCHASE, purchaseId));
|
||||
}
|
||||
|
||||
public void trackPurchaseStoreError(@BillingClient.BillingResponse int error)
|
||||
public void trackPurchasePreviewSelect(@NonNull String purchaseId, @NonNull String productId)
|
||||
{
|
||||
trackEvent(INAPP_PURCHASE_STORE_ERROR, params().add(ERROR, "Billing error: " + error));
|
||||
trackEvent(INAPP_PURCHASE_PREVIEW_SELECT, params().add(PRODUCT, productId)
|
||||
.add(PURCHASE, productId));
|
||||
}
|
||||
|
||||
public void trackPurchaseValidationError(@NonNull ValidationStatus status)
|
||||
public void trackPurchaseStoreError(@NonNull String purchaseId,
|
||||
@BillingClient.BillingResponse int error)
|
||||
{
|
||||
trackEvent(INAPP_PURCHASE_STORE_ERROR, params().add(ERROR, "Billing error: " + error)
|
||||
.add(PURCHASE, purchaseId));
|
||||
}
|
||||
|
||||
public void trackPurchaseValidationError(@NonNull String purchaseId, @NonNull ValidationStatus status)
|
||||
{
|
||||
if (status == ValidationStatus.VERIFIED)
|
||||
return;
|
||||
|
@ -1344,12 +1356,14 @@ public enum Statistics
|
|||
else
|
||||
return;
|
||||
|
||||
trackEvent(INAPP_PURCHASE_VALIDATION_ERROR, params().add(ERROR_CODE, errorCode));
|
||||
trackEvent(INAPP_PURCHASE_VALIDATION_ERROR, params().add(ERROR_CODE, errorCode)
|
||||
.add(PURCHASE, purchaseId));
|
||||
}
|
||||
|
||||
public void trackPurchaseProductDelivered(@NonNull String vendor)
|
||||
public void trackPurchaseProductDelivered(@NonNull String purchaseId, @NonNull String vendor)
|
||||
{
|
||||
trackEvent(INAPP_PURCHASE_PRODUCT_DELIVERED, params().add(VENDOR, vendor));
|
||||
trackEvent(INAPP_PURCHASE_PRODUCT_DELIVERED, params().add(VENDOR, vendor)
|
||||
.add(PURCHASE, purchaseId));
|
||||
}
|
||||
|
||||
public static ParameterBuilder params()
|
||||
|
|
Loading…
Add table
Reference in a new issue