diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppPrefs.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppPrefs.java index aff81c56ffed..89b16cb43267 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppPrefs.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppPrefs.java @@ -71,6 +71,8 @@ public enum DeletablePrefKey implements PrefKey { READER_TAG_TYPE, READER_TAG_WAS_FOLLOWING, + READER_ANALYTICS_COUNT_TAGS_TIMESTAMP, + // currently active tab on the main Reader screen when the user is in Reader READER_ACTIVE_TAB, @@ -1162,6 +1164,14 @@ public static void setReaderTagsUpdatedTimestamp(long timestamp) { setLong(DeletablePrefKey.READER_TAGS_UPDATE_TIMESTAMP, timestamp); } + public static long getReaderAnalyticsCountTagsTimestamp() { + return getLong(DeletablePrefKey.READER_ANALYTICS_COUNT_TAGS_TIMESTAMP, -1); + } + + public static void setReaderAnalyticsCountTagsTimestamp(long timestamp) { + setLong(DeletablePrefKey.READER_ANALYTICS_COUNT_TAGS_TIMESTAMP, timestamp); + } + public static long getReaderCssUpdatedTimestamp() { return getLong(DeletablePrefKey.READER_CSS_UPDATED_TIMESTAMP, 0); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderEvents.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderEvents.java index de72a22e2b40..2426057c20dc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderEvents.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderEvents.java @@ -62,6 +62,13 @@ public String getTagName() { } public static class FollowedBlogsChanged { + private final int mTotalSubscriptions; + public int getTotalSubscriptions() { + return mTotalSubscriptions; + } + public FollowedBlogsChanged(int totalSubscriptions) { + mTotalSubscriptions = totalSubscriptions; + } } public static class InterestTagsFetchEnded { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java index 5ad4b8714426..fcad46bae9e5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java @@ -118,6 +118,7 @@ import org.wordpress.android.ui.reader.subfilter.SubfilterListItem.SiteAll; import org.wordpress.android.ui.reader.tracker.ReaderTracker; import org.wordpress.android.ui.reader.usecases.ReaderSiteFollowUseCase.FollowSiteState.FollowStatusChanged; +import org.wordpress.android.ui.reader.utils.DateProvider; import org.wordpress.android.ui.reader.utils.ReaderUtils; import org.wordpress.android.ui.reader.viewmodels.ReaderModeInfo; import org.wordpress.android.ui.reader.viewmodels.ReaderPostListViewModel; @@ -948,6 +949,15 @@ public void onEventMainThread(FollowedTagsFetched event) { updateCurrentTag(); } } + + // Check last time we've bumped tags followed analytics for this user, + // and bumping again if > 1 hrs + long tagsUpdatedTimestamp = AppPrefs.getReaderAnalyticsCountTagsTimestamp(); + long now = new DateProvider().getCurrentDate().getTime(); + if (now - tagsUpdatedTimestamp > 1000 * 60 * 60) { // 1 hr + ReaderTracker.trackFollowedTagsCount(ReaderTagTable.getFollowedTags().size()); + AppPrefs.setReaderAnalyticsCountTagsTimestamp(now); + } } @SuppressWarnings("unused") @@ -959,6 +969,8 @@ && hasCurrentTag() && (getCurrentTag().isFollowedSites() || getCurrentTag().isDefaultInMemoryTag())) { refreshPosts(); } + + ReaderTracker.trackSubscribedSitesCount(event.getTotalSubscriptions()); } @Override diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java index e743d7f52bfa..9f1278a5667c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java @@ -335,9 +335,10 @@ public void run() { // changed if the server list doesn't have the same blogs as the local list // (ie: a blog has been followed/unfollowed since local was last updated) if (!localBlogs.hasSameBlogs(serverBlogs)) { + final int totalSites = jsonObject == null ? 0 : jsonObject.optInt("total_subscriptions", 0); ReaderPostTable.updateFollowedStatus(); AppLog.i(AppLog.T.READER, "reader blogs service > followed blogs changed"); - EventBus.getDefault().post(new ReaderEvents.FollowedBlogsChanged()); + EventBus.getDefault().post(new ReaderEvents.FollowedBlogsChanged(totalSites)); } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/tracker/ReaderTracker.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/tracker/ReaderTracker.kt index b40dfc0380ee..d935b29b57a9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/tracker/ReaderTracker.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/tracker/ReaderTracker.kt @@ -3,6 +3,7 @@ package org.wordpress.android.ui.reader.tracker import android.net.Uri import androidx.annotation.MainThread import org.wordpress.android.analytics.AnalyticsTracker +import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.models.ReaderPost import org.wordpress.android.models.ReaderTag import org.wordpress.android.ui.prefs.AppPrefsWrapper @@ -465,6 +466,23 @@ class ReaderTracker @Inject constructor( AnalyticsTracker.track(stat, properties) } + private fun trackFollowedCount(type: String, numberOfItems: Int) { + val props: MutableMap = HashMap() + props["type"] = type + props["count"] = numberOfItems.toString() + AnalyticsTracker.track(Stat.READER_FOLLOWING_FETCHED, props) + } + + @JvmStatic + fun trackFollowedTagsCount(numberOfItems: Int) { + trackFollowedCount("tags", numberOfItems) + } + + @JvmStatic + fun trackSubscribedSitesCount(numberOfItems: Int) { + trackFollowedCount("sites", numberOfItems) + } + fun isUserProfileSource(source: String): Boolean { return (source == SOURCE_READER_LIKE_LIST_USER_PROFILE || source == SOURCE_NOTIF_LIKE_LIST_USER_PROFILE || diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index 27d27b6fb851..563436324272 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -80,6 +80,7 @@ public enum Stat { READER_SAVED_POST_OPENED_FROM_SAVED_POST_LIST, READER_SAVED_POST_OPENED_FROM_OTHER_POST_LIST, READER_SITE_SHARED, + READER_FOLLOWING_FETCHED, STATS_ACCESSED, STATS_ACCESS_ERROR, STATS_PERIOD_ACCESSED, diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index e22e50fc67b3..7194bb9ed3a6 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -717,6 +717,8 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "reader_saved_post_opened"; case READER_SITE_SHARED: return "reader_site_shared"; + case READER_FOLLOWING_FETCHED: + return "reader_following_fetched"; case EDITOR_CREATED_POST: return "editor_post_created"; case EDITOR_SAVED_DRAFT: