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

Update stats analytics #20194

Merged
merged 17 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
import org.wordpress.android.ui.stats.StatsTimeframe;
import org.wordpress.android.ui.stats.StatsViewType;
import org.wordpress.android.ui.stats.refresh.StatsActivity;
import org.wordpress.android.ui.stats.refresh.StatsActivity.StatsLaunchedFrom;
import org.wordpress.android.ui.stats.refresh.StatsViewAllActivity;
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection;
import org.wordpress.android.ui.stats.refresh.lists.detail.StatsDetailActivity;
Expand Down Expand Up @@ -501,21 +502,23 @@ public static void openEditorForReblog(
addNewPostForResult(editorIntent, activity, site, false, reblogSource, -1, null);
}

public static void viewStatsInNewStack(Context context, SiteModel site) {
viewStatsInNewStack(context, site, null);
public static void viewStatsInNewStack(Context context, SiteModel site, @NonNull StatsLaunchedFrom launchedFrom) {
viewStatsInNewStack(context, site, null, launchedFrom);
}

public static void viewStatsInNewStack(Context context, SiteModel site, @Nullable StatsTimeframe statsTimeframe) {
viewStatsInNewStack(context, site, statsTimeframe, null);
public static void viewStatsInNewStack(Context context, SiteModel site, @Nullable StatsTimeframe statsTimeframe,
@NonNull StatsLaunchedFrom launchedFrom) {
viewStatsInNewStack(context, site, statsTimeframe, null, launchedFrom);
}

public static void viewStatsInNewStack(Context context, SiteModel site, @Nullable StatsTimeframe statsTimeframe,
@Nullable String period) {
@Nullable String period, @NonNull StatsLaunchedFrom launchedFrom) {
if (site == null) {
handleMissingSite(context);
return;
}
runIntentOverMainActivityInNewStack(context, StatsActivity.buildIntent(context, site, statsTimeframe, period));
runIntentOverMainActivityInNewStack(context,
StatsActivity.buildIntent(context, site, statsTimeframe, period, launchedFrom));
}

private static void handleMissingSite(Context context) {
Expand All @@ -537,9 +540,11 @@ public static PendingIntent buildStatsPendingIntentOverMainActivityInNewStack(Co
@Nullable StatsTimeframe timeframe,
@Nullable String period,
@Nullable NotificationType type,
@NonNull
StatsLaunchedFrom launchedFrom,
int requestCode, int flags) {
return buildPendingIntentOverMainActivityInNewStack(context,
StatsActivity.buildIntent(context, site, timeframe, period, type), requestCode, flags);
StatsActivity.buildIntent(context, site, timeframe, period, launchedFrom, type), requestCode, flags);
}

private static PendingIntent buildPendingIntentOverMainActivityInNewStack(Context context, Intent intent,
Expand Down Expand Up @@ -586,33 +591,34 @@ public static void viewSavedPostsListInReader(Context context) {
context.startActivity(intent);
}

public static void viewBlogStats(Context context, SiteModel site) {
public static void viewBlogStats(Context context, SiteModel site, @NonNull StatsLaunchedFrom from) {
if (site == null) {
AppLog.e(T.STATS, "SiteModel is null when opening the stats.");
AnalyticsTracker.track(
STATS_ACCESS_ERROR,
ActivityLauncher.class.getName(),
"NullPointerException",
"Failed to open Stats because of the null SiteModel"
);
);
ToastUtils.showToast(context, R.string.stats_cannot_be_started, ToastUtils.Duration.SHORT);
} else {
StatsActivity.start(context, site);
StatsActivity.start(context, site, from);
}
}

public static void viewBlogStatsForTimeframe(Context context, SiteModel site, StatsTimeframe statsTimeframe) {
public static void viewBlogStatsForTimeframe(Context context, SiteModel site, StatsTimeframe statsTimeframe,
@NonNull StatsLaunchedFrom from) {
if (site == null) {
AppLog.e(T.STATS, "SiteModel is null when opening the stats.");
AnalyticsTracker.track(
STATS_ACCESS_ERROR,
ActivityLauncher.class.getName(),
"NullPointerException",
"Failed to open Stats because of the null SiteModel"
);
);
ToastUtils.showToast(context, R.string.stats_cannot_be_started, ToastUtils.Duration.SHORT);
} else {
StatsActivity.start(context, site, statsTimeframe);
StatsActivity.start(context, site, statsTimeframe, from);
}
}

Expand All @@ -636,19 +642,20 @@ public static void viewInsightsManagement(Context context, int localSiteId) {
context.startActivity(intent);
}

public static void viewBlogStatsAfterJetpackSetup(Context context, SiteModel site) {
public static void viewBlogStatsAfterJetpackSetup(Context context, SiteModel site,
@NonNull StatsLaunchedFrom launchedFrom) {
if (site == null) {
AppLog.e(T.STATS, "SiteModel is null when opening the stats.");
AnalyticsTracker.track(
STATS_ACCESS_ERROR,
ActivityLauncher.class.getName(),
"NullPointerException",
"Failed to open Stats because of the null SiteModel"
);
);
ToastUtils.showToast(context, R.string.stats_cannot_be_started, ToastUtils.Duration.SHORT);
return;
}
StatsActivity.start(context, site);
StatsActivity.start(context, site, launchedFrom);
}

public static void viewConnectJetpackForStats(Context context, SiteModel site) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.login.LoginMode;
import org.wordpress.android.ui.accounts.LoginActivity;
import org.wordpress.android.ui.stats.refresh.StatsActivity.StatsLaunchedFrom;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.SiteUtils;
import org.wordpress.android.util.ToastUtils;
Expand Down Expand Up @@ -140,7 +141,7 @@ private void finishAndGoBackToSource() {
if (mSource == JetpackConnectionSource.STATS) {
SiteModel site = (SiteModel) getIntent().getSerializableExtra(SITE);
mDispatcher.dispatch(SiteActionBuilder.newFetchSitesAction(SiteUtils.getFetchSitesPayload()));
ActivityLauncher.viewBlogStatsAfterJetpackSetup(this, site);
ActivityLauncher.viewBlogStatsAfterJetpackSetup(this, site, StatsLaunchedFrom.JETPACK_CONNECTION);
}
finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.fluxc.model.SiteModel;
import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper;
import org.wordpress.android.ui.stats.refresh.StatsActivity.StatsLaunchedFrom;
import org.wordpress.android.util.AppLog;

import javax.inject.Inject;
Expand Down Expand Up @@ -35,7 +36,7 @@ public void showTargetScreen(String action, Activity activity, SiteModel current
if (mJetpackFeatureRemovalPhaseHelper.shouldShowStaticPage()) {
ActivityLauncher.showJetpackStaticPoster(activity);
} else {
ActivityLauncher.viewBlogStats(activity, currentSite);
ActivityLauncher.viewBlogStats(activity, currentSite, StatsLaunchedFrom.SHORTCUT);
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction.ViewP
import org.wordpress.android.ui.sitecreation.misc.SiteCreationSource.DEEP_LINK
import org.wordpress.android.ui.sitemonitor.SiteMonitorType
import org.wordpress.android.ui.stats.StatsTimeframe
import org.wordpress.android.ui.stats.refresh.StatsActivity
import org.wordpress.android.util.UriWrapper
import javax.inject.Inject

Expand Down Expand Up @@ -61,12 +62,20 @@ class DeepLinkNavigator
activity,
navigateAction.statsTimeframe
)
is OpenStatsForSite -> ActivityLauncher.viewStatsInNewStack(activity, navigateAction.site)

is OpenStatsForSite -> ActivityLauncher.viewStatsInNewStack(
activity,
navigateAction.site,
StatsActivity.StatsLaunchedFrom.LINK
)

is OpenStatsForSiteAndTimeframe -> ActivityLauncher.viewStatsInNewStack(
activity,
navigateAction.site,
navigateAction.statsTimeframe
navigateAction.statsTimeframe,
StatsActivity.StatsLaunchedFrom.LINK
)

OpenReader -> ActivityLauncher.viewReaderInNewStack(activity)
is OpenInReader -> ActivityLauncher.viewPostDeeplinkInNewStack(activity, navigateAction.uri.uri)
is ViewPostInReader -> ActivityLauncher.viewReaderPostDetailInNewStack(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
import org.wordpress.android.ui.review.ReviewViewModel;
import org.wordpress.android.ui.sitecreation.misc.SiteCreationSource;
import org.wordpress.android.ui.stats.StatsTimeframe;
import org.wordpress.android.ui.stats.refresh.StatsActivity.StatsLaunchedFrom;
import org.wordpress.android.ui.stories.intro.StoriesIntroDialogFragment;
import org.wordpress.android.ui.uploads.UploadActionUseCase;
import org.wordpress.android.ui.uploads.UploadUtils;
Expand Down Expand Up @@ -944,9 +945,10 @@ private void handleOpenPageIntent(@NonNull Intent intent) {
}
if (intent.hasExtra(ARG_STATS_TIMEFRAME)) {
ActivityLauncher.viewBlogStatsForTimeframe(this, getSelectedSite(),
(StatsTimeframe) intent.getSerializableExtra(ARG_STATS_TIMEFRAME));
(StatsTimeframe) intent.getSerializableExtra(ARG_STATS_TIMEFRAME),
StatsLaunchedFrom.LINK);
} else {
ActivityLauncher.viewBlogStats(this, getSelectedSite());
ActivityLauncher.viewBlogStats(this, getSelectedSite(), StatsLaunchedFrom.LINK);
}
break;
case ARG_PAGES:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import org.wordpress.android.ui.quickstart.QuickStartTracker
import org.wordpress.android.ui.reader.ReaderActivityLauncher
import org.wordpress.android.ui.reader.tracker.ReaderTracker
import org.wordpress.android.ui.stats.StatsTimeframe
import org.wordpress.android.ui.stats.refresh.StatsActivity
import org.wordpress.android.ui.uploads.UploadService
import org.wordpress.android.ui.uploads.UploadUtilsWrapper
import org.wordpress.android.ui.utils.TitleSubtitleSnackbarSpannable
Expand Down Expand Up @@ -607,7 +608,12 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment),
action.quickStartEvent
)
is SiteNavigationAction.OpenUnifiedComments -> ActivityLauncher.viewUnifiedComments(activity, action.site)
is SiteNavigationAction.OpenStats -> ActivityLauncher.viewBlogStats(activity, action.site)
is SiteNavigationAction.OpenStats -> ActivityLauncher.viewBlogStats(
activity,
action.site,
StatsActivity.StatsLaunchedFrom.QUICK_ACTIONS
)

is SiteNavigationAction.ConnectJetpackForStats ->
ActivityLauncher.viewConnectJetpackForStats(activity, action.site)
is SiteNavigationAction.StartWPComLoginForJetpackStats ->
Expand Down Expand Up @@ -667,8 +673,14 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment),
ActivityLauncher.viewCurrentBlogPostsOfType(requireActivity(), action.site, PostListType.DRAFTS)
is SiteNavigationAction.EditScheduledPost ->
ActivityLauncher.viewCurrentBlogPostsOfType(requireActivity(), action.site, PostListType.SCHEDULED)
is SiteNavigationAction.OpenStatsInsights ->
ActivityLauncher.viewBlogStatsForTimeframe(requireActivity(), action.site, StatsTimeframe.INSIGHTS)

is SiteNavigationAction.OpenStatsInsights -> ActivityLauncher.viewBlogStatsForTimeframe(
requireActivity(),
action.site,
StatsTimeframe.INSIGHTS,
StatsActivity.StatsLaunchedFrom.TODAY_STATS_CARD
)

is SiteNavigationAction.OpenExternalUrl ->
ActivityLauncher.openUrlExternal(requireActivity(), action.url)
is SiteNavigationAction.OpenUrlInWebView ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import org.wordpress.android.ui.mysite.items.listitem.ListItemAction
import org.wordpress.android.ui.pages.SnackbarMessageHolder
import org.wordpress.android.ui.prefs.SiteSettingsFragment
import org.wordpress.android.ui.quickstart.QuickStartMySitePrompts
import org.wordpress.android.ui.stats.refresh.StatsActivity
import org.wordpress.android.ui.utils.ListItemInteraction
import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.util.LocaleManager
Expand Down Expand Up @@ -143,7 +144,12 @@ class MenuActivity : AppCompatActivity() {
is SiteNavigationAction.OpenMedia -> ActivityLauncher.viewCurrentBlogMedia(this, action.site)
is SiteNavigationAction.OpenMeScreen -> ActivityLauncher.viewMeActivityForResult(this)
is SiteNavigationAction.OpenUnifiedComments -> ActivityLauncher.viewUnifiedComments(this, action.site)
is SiteNavigationAction.OpenStats -> ActivityLauncher.viewBlogStats(this, action.site)
is SiteNavigationAction.OpenStats -> ActivityLauncher.viewBlogStats(
this,
action.site,
StatsActivity.StatsLaunchedFrom.ROW
)

is SiteNavigationAction.OpenDomains -> ActivityLauncher.viewDomainsDashboardActivity(
this,
action.site
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.wordpress.android.ui.reader.comments.ThreadedCommentsActionSource;
import org.wordpress.android.ui.reader.tracker.ReaderTracker;
import org.wordpress.android.ui.stats.StatsViewType;
import org.wordpress.android.ui.stats.refresh.StatsActivity.StatsLaunchedFrom;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.ToastUtils;
Expand Down Expand Up @@ -504,7 +505,7 @@ private void showStatsActivityForSite(@NonNull SiteModel site, FormattableRangeT
ActivityLauncher.viewAllTabbedInsightsStats(this, StatsViewType.FOLLOWERS, 0,
site.getId());
} else {
ActivityLauncher.viewBlogStats(this, site);
ActivityLauncher.viewBlogStats(this, site, StatsLaunchedFrom.NOTIFICATION);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.wordpress.android.ui.reader.comments.ThreadedCommentsActionSource.ACT
import org.wordpress.android.ui.reader.tracker.ReaderTracker
import org.wordpress.android.ui.reader.utils.ReaderUtils
import org.wordpress.android.ui.stats.StatsViewType.FOLLOWERS
import org.wordpress.android.ui.stats.refresh.StatsActivity
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T.API
import org.wordpress.android.util.ToastUtils
Expand Down Expand Up @@ -117,7 +118,7 @@ class FormattableContentClickHandler @Inject constructor(
if (rangeType == FormattableRangeType.FOLLOW) {
ActivityLauncher.viewAllTabbedInsightsStats(activity, FOLLOWERS, 0, site.id)
} else {
ActivityLauncher.viewBlogStats(activity, site)
ActivityLauncher.viewBlogStats(activity, site, StatsActivity.StatsLaunchedFrom.ACTIVITY_LOG)
staskus marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class StatsActivity : LocaleAwareActivity() {
context: Context,
site: SiteModel,
statsTimeframe: StatsTimeframe? = null,
period: String? = null
) = context.startActivity(buildIntent(context, site, statsTimeframe, period))
period: String? = null,
launchedFrom: StatsLaunchedFrom
) = context.startActivity(buildIntent(context, site, statsTimeframe, period, launchedFrom))

@JvmStatic
@JvmOverloads
Expand All @@ -79,17 +80,26 @@ class StatsActivity : LocaleAwareActivity() {
site: SiteModel,
statsTimeframe: StatsTimeframe? = null,
period: String? = null,
launchedFrom: StatsLaunchedFrom,
notificationType: NotificationType? = null
) = Intent(context, StatsActivity::class.java).apply {
putExtra(WordPress.LOCAL_SITE_ID, site.id)
statsTimeframe?.let { putExtra(ARG_DESIRED_TIMEFRAME, it) }
period?.let { putExtra(INITIAL_SELECTED_PERIOD_KEY, it) }
putExtra(ARG_LAUNCHED_FROM, launchedFrom)
notificationType?.let { putExtra(ARG_NOTIFICATION_TYPE, it) }
}
}

enum class StatsLaunchedFrom {
STATS_WIDGET,
NOTIFICATIONS
enum class StatsLaunchedFrom(val value: String) {
QUICK_ACTIONS("quick_actions"),
TODAY_STATS_CARD("today_stats_card"),
ROW("row"),
WIDGET("widget"),
NOTIFICATION("notification"),
LINK("link"),
SHORTCUT("shortcut"),
ACTIVITY_LOG("activity_log"),
JETPACK_CONNECTION("jetpack_connection")
}
}
Loading
Loading