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 eb9e37a9e514..eb393116dbd7 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, @@ -1161,6 +1163,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/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java index 2da410a95ab6..612c07b5dc1e 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 @@ -117,6 +117,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; @@ -945,6 +946,15 @@ public void onEventMainThread(ReaderEvents.FollowedTagsChanged 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") @@ -956,6 +966,10 @@ && hasCurrentTag() && (getCurrentTag().isFollowedSites() || getCurrentTag().isDefaultInMemoryTag())) { refreshPosts(); } + + ReaderBlogTable.getFollowedBlogs(); + ReaderTracker.trackFollowedTagsCount(ReaderTagTable.getFollowedTags().size()); + AppPrefs.setReaderAnalyticsCountTagsTimestamp(now); } @Override 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..2f6aa8b836a2 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,22 @@ class ReaderTracker @Inject constructor( AnalyticsTracker.track(stat, properties) } + @JvmStatic + fun trackFollowedTagsCount(numberOfItems: Int) { + val props: MutableMap = HashMap() + props["type"] = "tags" + props["count"] = numberOfItems.toString() + AnalyticsTracker.track(Stat.READER_FOLLOWING_FETCHED, props) + } + + @JvmStatic + fun trackFollowedSitesCount(numberOfItems: Int) { + val props: MutableMap = HashMap() + props["type"] = "sites" + props["count"] = numberOfItems.toString() + AnalyticsTracker.track(Stat.READER_FOLLOWING_FETCHED, props) + } + 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 0fe9a77f7d2e..f27b1f958e75 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 2f946200e424..63c9b14aba55 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: