Skip to content

Commit

Permalink
Merge pull request #20303 from wordpress-mobile/issue-19836-Add-follo…
Browse files Browse the repository at this point in the history
…wed-sites-and-tags-to-Reader-analytics-events

[Reader] Add subscribed sites and followed tags to analytics
  • Loading branch information
daniloercoli authored Mar 1, 2024
2 parents 750267b + ee22402 commit eadd3de
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -959,6 +969,8 @@ && hasCurrentTag()
&& (getCurrentTag().isFollowedSites() || getCurrentTag().isDefaultInMemoryTag())) {
refreshPosts();
}

ReaderTracker.trackSubscribedSitesCount(event.getTotalSubscriptions());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -465,6 +466,23 @@ class ReaderTracker @Inject constructor(
AnalyticsTracker.track(stat, properties)
}

private fun trackFollowedCount(type: String, numberOfItems: Int) {
val props: MutableMap<String, String> = 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 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit eadd3de

Please sign in to comment.