[android][statistics] Url params from deep links are sent into statistics

This commit is contained in:
Arsentiy Milchakov 2020-02-03 14:04:22 +03:00 committed by Aleksandr Zatsepin
parent a6ce311126
commit b5a9c7f49f
8 changed files with 103 additions and 85 deletions

View file

@ -64,7 +64,6 @@ import com.mapswithme.maps.editor.ReportFragment;
import com.mapswithme.maps.gallery.Items;
import com.mapswithme.maps.intent.Factory;
import com.mapswithme.maps.intent.MapTask;
import com.mapswithme.maps.intent.RegularMapTask;
import com.mapswithme.maps.location.CompassData;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.maplayer.MapLayerCompositeController;
@ -1035,7 +1034,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (category == null)
throw new IllegalArgumentException("Category not found in bundle");
MapTask mapTask = new RegularMapTask()
addTask(new MapTask()
{
private static final long serialVersionUID = -7417385158050827655L;
@ -1045,8 +1044,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
target.showBookmarkCategory(category);
return true;
}
};
addTask(mapTask);
});
closePlacePage();
}
@ -1133,7 +1131,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
@Override
public void onRouteToDiscoveredObject(@NonNull final MapObject object)
{
addTask(new RegularMapTask()
addTask(new MapTask()
{
private static final long serialVersionUID = -219799471997583494L;
@ -1151,7 +1149,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
@Override
public void onShowDiscoveredObject(@NonNull final MapObject object)
{
addTask(new RegularMapTask()
addTask(new MapTask()
{
private static final long serialVersionUID = 7499190617762270631L;
@ -1967,7 +1965,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void adjustCompassAndTraffic(final int offsetY)
{
addTask(new RegularMapTask()
addTask(new MapTask()
{
private static final long serialVersionUID = 9177064181621376624L;

View file

@ -46,11 +46,4 @@ public class BackUrlMapTaskWrapper implements MapTask
{
return new BackUrlMapTaskWrapper(task, url);
}
@NonNull
@Override
public String toStatisticValue()
{
return mMapTask.toStatisticValue();
}
}

View file

@ -760,21 +760,19 @@ public class Factory
return value;
}
public static class BookmarksSubscriptionTask implements MapTask
public static class BookmarksSubscriptionTask extends UrlTaskWithStatistics
{
private static final long serialVersionUID = 8378582625122063605L;
@NonNull
private final String mUrl;
BookmarksSubscriptionTask(@NonNull String url)
{
mUrl = url;
super(url);
}
@Override
public boolean run(@NonNull MwmActivity target)
{
Uri uri = Uri.parse(mUrl);
Uri uri = Uri.parse(getUrl());
String serverId = uri.getQueryParameter(PurchaseUtils.GROUPS);
if (TextUtils.isEmpty(serverId))
return false;
@ -804,21 +802,19 @@ public class Factory
}
}
public static class ImportBookmarkCatalogueTask implements MapTask
public static class ImportBookmarkCatalogueTask extends UrlTaskWithStatistics
{
private static final long serialVersionUID = 5363722491377575159L;
@NonNull
private final String mUrl;
ImportBookmarkCatalogueTask(@NonNull String url)
{
mUrl = url;
super(url);
}
@Override
public boolean run(@NonNull MwmActivity target)
{
BookmarkCategoriesActivity.startForResult(target, BookmarksPageFactory.DOWNLOADED.ordinal(), mUrl);
BookmarkCategoriesActivity.startForResult(target, BookmarksPageFactory.DOWNLOADED.ordinal(), getUrl());
return true;
}
@ -830,7 +826,7 @@ public class Factory
}
}
public static class GuidesPageToOpenTask extends BaseUrlTask
public static class GuidesPageToOpenTask extends UrlTaskWithStatistics
{
private static final long serialVersionUID = 8388101038319062165L;
@ -870,13 +866,6 @@ public class Factory
target.showIntroductionScreenForDeeplink(getUrl(), IntroductionScreenFactory.FREE_GUIDE);
return true;
}
@NonNull
@Override
public String toStatisticValue()
{
throw new UnsupportedOperationException("This task not statistic tracked!");
}
}
public static class GuidesPageToOpenIntroductionTask extends BaseUrlTask
@ -895,13 +884,6 @@ public class Factory
target.showIntroductionScreenForDeeplink(deeplink, IntroductionScreenFactory.GUIDES_PAGE);
return true;
}
@NonNull
@Override
public String toStatisticValue()
{
throw new UnsupportedOperationException("This task not statistic tracked!");
}
}
abstract static class BaseUrlTask implements MapTask
@ -922,34 +904,58 @@ public class Factory
}
}
public static class OpenUrlTask implements MapTask
abstract static class UrlTaskWithStatistics extends MapTaskWithStatistics
{
private static final long serialVersionUID = -8661639898700431066L;
@NonNull
private final String mUrl;
UrlTaskWithStatistics(@NonNull String url)
{
Utils.checkNotNull(url);
mUrl = url;
}
@Override
@NonNull
public Statistics.ParameterBuilder toStatisticParams()
{
return Statistics.makeParametersFromTypeAndUrl(toStatisticValue(), mUrl);
}
@NonNull
String getUrl()
{
return mUrl;
}
}
public static class OpenUrlTask extends UrlTaskWithStatistics
{
private static final long serialVersionUID = -7257820771228127413L;
private static final int SEARCH_IN_VIEWPORT_ZOOM = 16;
@NonNull
private final String mUrl;
@NonNull
private final String mStatisticValue;
OpenUrlTask(@NonNull String url, @NonNull String statisticValue)
{
Utils.checkNotNull(url);
mUrl = url;
super(url);
mStatisticValue = statisticValue;
}
@Override
public boolean run(@NonNull MwmActivity target)
{
final @ParsedUrlMwmRequest.ParsingResult int result = Framework.nativeParseAndSetApiUrl(mUrl);
final @ParsedUrlMwmRequest.ParsingResult int result = Framework.nativeParseAndSetApiUrl(getUrl());
switch (result)
{
case ParsedUrlMwmRequest.RESULT_INCORRECT:
// TODO: Kernel recognizes "mapsme://", "mwm://" and "mapswithme://" schemas only!!!
return MapFragment.nativeShowMapForUrl(mUrl);
return MapFragment.nativeShowMapForUrl(getUrl());
case ParsedUrlMwmRequest.RESULT_MAP:
return MapFragment.nativeShowMapForUrl(mUrl);
return MapFragment.nativeShowMapForUrl(getUrl());
case ParsedUrlMwmRequest.RESULT_ROUTE:
final ParsedRoutingData data = Framework.nativeGetParsedRoutingData();
@ -991,7 +997,7 @@ public class Factory
}
}
public static class ShowCountryTask implements MapTask
public static class ShowCountryTask extends MapTaskWithStatistics
{
private static final long serialVersionUID = 256630934543189768L;
private final String mCountryId;
@ -1016,7 +1022,7 @@ public class Factory
}
}
public static class ShowBookmarkCategoryTask extends RegularMapTask
public static class ShowBookmarkCategoryTask implements MapTask
{
private static final long serialVersionUID = 8285565041410550281L;
final long mCategoryId;
@ -1033,7 +1039,7 @@ public class Factory
}
}
static abstract class BaseUserMarkTask extends RegularMapTask
static abstract class BaseUserMarkTask implements MapTask
{
private static final long serialVersionUID = -3348320422813422144L;
final long mCategoryId;
@ -1080,7 +1086,7 @@ public class Factory
}
}
public static class ShowPointTask implements MapTask
public static class ShowPointTask extends MapTaskWithStatistics
{
private static final long serialVersionUID = -2467635346469323664L;
private final double mLat;
@ -1108,7 +1114,7 @@ public class Factory
}
}
public static class BuildRouteTask implements MapTask
public static class BuildRouteTask extends MapTaskWithStatistics
{
private static final long serialVersionUID = 5301468481040195957L;
private final double mLatTo;
@ -1213,7 +1219,7 @@ public class Factory
}
}
public static class RestoreRouteTask extends RegularMapTask
public static class RestoreRouteTask implements MapTask
{
private static final long serialVersionUID = 6123893958975977040L;
@ -1225,7 +1231,7 @@ public class Factory
}
}
public static class ShowUGCEditorTask extends RegularMapTask
public static class ShowUGCEditorTask implements MapTask
{
private static final long serialVersionUID = 1636712824900113568L;
// Nullable because of possible serialization from previous incompatible version of class.
@ -1256,7 +1262,7 @@ public class Factory
}
}
public static class ShowDialogTask extends RegularMapTask
public static class ShowDialogTask implements MapTask
{
private static final long serialVersionUID = 1548931513812565018L;
@NonNull

View file

@ -7,7 +7,7 @@ import com.mapswithme.util.statistics.StatisticValueConverter;
import java.io.Serializable;
public interface MapTask extends Serializable, StatisticValueConverter<String>
public interface MapTask extends Serializable
{
boolean run(@NonNull MwmActivity target);
}

View file

@ -0,0 +1,16 @@
package com.mapswithme.maps.intent;
import androidx.annotation.NonNull;
import com.mapswithme.util.statistics.StatisticValueConverter;
import com.mapswithme.util.statistics.Statistics;
abstract class MapTaskWithStatistics implements MapTask, StatisticValueConverter<String>
{
private static final long serialVersionUID = 3354057363011918229L;
@NonNull
public Statistics.ParameterBuilder toStatisticParams()
{
return Statistics.makeParametersFromType(toStatisticValue());
}
}

View file

@ -1,15 +0,0 @@
package com.mapswithme.maps.intent;
import androidx.annotation.NonNull;
public abstract class RegularMapTask implements MapTask
{
private static final long serialVersionUID = -6799622370628032853L;
@NonNull
@Override
public String toStatisticValue()
{
throw new UnsupportedOperationException("This task '" + this + "' not tracked in statistic!");
}
}

View file

@ -9,9 +9,9 @@ public class StatisticMapTaskWrapper implements MapTask
{
private static final long serialVersionUID = 7604577952712453816L;
@NonNull
private final MapTask mMapTask;
private final MapTaskWithStatistics mMapTask;
private StatisticMapTaskWrapper(@NonNull MapTask mapTask)
private StatisticMapTaskWrapper(@NonNull MapTaskWithStatistics mapTask)
{
mMapTask = mapTask;
}
@ -23,22 +23,15 @@ public class StatisticMapTaskWrapper implements MapTask
boolean firstLaunch = MwmApplication.from(target).isFirstLaunch();
if (success)
Statistics.INSTANCE.trackDeeplinkEvent(Statistics.EventName.DEEPLINK_CALL,
mMapTask.toStatisticValue(), firstLaunch);
mMapTask.toStatisticParams(), firstLaunch);
else
Statistics.INSTANCE.trackDeeplinkEvent(Statistics.EventName.DEEPLINK_CALL_MISSED,
toStatisticValue(), firstLaunch);
mMapTask.toStatisticParams(), firstLaunch);
return success;
}
@NonNull
@Override
public String toStatisticValue()
{
return mMapTask.toStatisticValue();
}
@NonNull
static MapTask wrap(@NonNull MapTask task)
static MapTask wrap(@NonNull MapTaskWithStatistics task)
{
return new StatisticMapTaskWrapper(task);
}

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Pair;
@ -1770,9 +1771,35 @@ public enum Statistics
trackEvent(GUIDES_TRACK_SELECT, params().add(SERVER_ID, serverId), STATISTICS_CHANNEL_REALTIME);
}
public void trackDeeplinkEvent(@NonNull String event, @NonNull String type, boolean isFirstLaunch)
public void trackDeeplinkEvent(@NonNull String event, @NonNull ParameterBuilder params,
boolean isFirstLaunch)
{
trackEvent(event, params().add(TYPE, type).add(FIRST_LAUNCH, isFirstLaunch ? TRUE : FALSE));
trackEvent(event, params.add(FIRST_LAUNCH, isFirstLaunch ? TRUE : FALSE));
}
@NonNull
public static ParameterBuilder makeParametersFromType(@NonNull String type)
{
return params().add(TYPE, type);
}
@NonNull
public static ParameterBuilder makeParametersFromTypeAndUrl(@NonNull String type, @NonNull String url)
{
Statistics.ParameterBuilder result = params();
Uri uri = Uri.parse(url);
for (String name : uri.getQueryParameterNames())
{
if (name.startsWith("utm_") || name.equals("booking_aid"))
{
String value = uri.getQueryParameter(name);
result.add(name, value == null ? "" : value);
}
}
result.add(TYPE, type);
return result;
}
public static ParameterBuilder params()