Skip to content

Commit

Permalink
Track the number of followed tags when the "FollowedTagsChanged" even…
Browse files Browse the repository at this point in the history
…t is fired

Note that we're aware of an underlying issue with the FollowedTagsChanged event being fired excessively, even when the tags have not changed. To address this, I've implemented a guard to prevent excessive analytics tracking, currently set to 1 hour. This guard does not verify the previous number of tags sent to analytics. Considering the frequent triggering of "tags changed," this seems to be a reasonable compromise.
  • Loading branch information
daniloercoli committed Feb 20, 2024
1 parent db5bbc7 commit 52a6334
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
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 @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -956,6 +966,10 @@ && hasCurrentTag()
&& (getCurrentTag().isFollowedSites() || getCurrentTag().isDefaultInMemoryTag())) {
refreshPosts();
}

ReaderBlogTable.getFollowedBlogs();
ReaderTracker.trackFollowedTagsCount(ReaderTagTable.getFollowedTags().size());
AppPrefs.setReaderAnalyticsCountTagsTimestamp(now);
}

@Override
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,22 @@ class ReaderTracker @Inject constructor(
AnalyticsTracker.track(stat, properties)
}

@JvmStatic
fun trackFollowedTagsCount(numberOfItems: Int) {
val props: MutableMap<String, String> = HashMap()
props["type"] = "tags"
props["count"] = numberOfItems.toString()
AnalyticsTracker.track(Stat.READER_FOLLOWING_FETCHED, props)
}

@JvmStatic
fun trackFollowedSitesCount(numberOfItems: Int) {
val props: MutableMap<String, String> = 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 ||
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 52a6334

Please sign in to comment.