Skip to content

Commit

Permalink
+ Adds: site details to analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
AjeshRPai committed Apr 26, 2024
1 parent c90f31b commit 3066fda
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ import org.wordpress.android.widgets.AppRatingDialog
import org.wordpress.android.workers.WordPressWorkersFactory
import java.io.File
import java.io.IOException
import java.lang.Exception
import java.net.CookieManager
import java.util.Date
import javax.inject.Inject
Expand Down Expand Up @@ -259,6 +258,7 @@ class AppInitializer @Inject constructor(
val selectedSiteLocalId = selectedSiteRepository.getSelectedSiteLocalId(true)
val site = siteStore.getSiteByLocalId(selectedSiteLocalId)
site?.let {
AnalyticsUtils.refreshMetadataAfterSiteSelected(accountStore, siteStore, site)
dispatcher.dispatch(SiteActionBuilder.newFetchSiteAction(site))
// Reload editor details from the remote backend
if (!AppPrefs.isDefaultAppWideEditorPreferenceSet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.SharedPreferences;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.MimeTypeMap;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -182,6 +183,30 @@ public static void refreshMetadata(AccountStore accountStore, SiteStore siteStor
AnalyticsTracker.refreshMetadata(metadata);
}

public static void refreshMetadataAfterSiteSelected(AccountStore accountStore, SiteStore siteStore, SiteModel site) {
AnalyticsMetadata metadata = new AnalyticsMetadata();

metadata.setUserConnected(FluxCUtils.isSignedInWPComOrHasWPOrgSite(accountStore, siteStore));
metadata.setWordPressComUser(accountStore.hasAccessToken());
metadata.setJetpackUser(isJetpackUser(siteStore));
metadata.setNumBlogs(siteStore.getSitesCount());
metadata.setUsername(accountStore.getAccount().getUserName());
metadata.setPlanShortName(site.getPlanShortName());
metadata.setIsJetpackConnectedSite(site.isJetpackConnected());
metadata.setEmail(accountStore.getAccount().getEmail());
String scheme = BuildConfig.DEBUG ? "debug" : BuildConfig.FLAVOR;
metadata.setAppScheme(scheme);
if (siteStore.hasSite()) {
metadata.setGutenbergEnabled(isGutenbergEnabledOnAnySite(siteStore.getSites()));
}

Log.e("isJetpack user", "" + metadata.isJetpackUser());
Log.e("isJetpack site", "" + metadata.getIsJetpackConnectedSite());
Log.e("plan short name", "" + metadata.getPlanShortName());

AnalyticsTracker.refreshMetadata(metadata);
}

@VisibleForTesting
protected static boolean isGutenbergEnabledOnAnySite(List<SiteModel> sites) {
for (SiteModel currentSite : sites) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class AnalyticsMetadata {
private String mAppScheme = "";
private boolean mIsGutenbergEnabled;
private boolean mIsGutenbergEnabledVariableSet;
// Plan short name of the site, if its a self hosted site , then empty string
private String planShortName;
// If the site is connected to Jetpack
private boolean isJetpackConnectedSite;

public AnalyticsMetadata() {
}
Expand Down Expand Up @@ -91,4 +95,20 @@ public void setGutenbergEnabled(boolean gutenbergEnabled) {
this.mIsGutenbergEnabled = gutenbergEnabled;
this.mIsGutenbergEnabledVariableSet = true;
}

public String getPlanShortName() {
return planShortName;
}

public void setPlanShortName(String planShortName) {
this.planShortName = planShortName;
}

public boolean getIsJetpackConnectedSite() {
return isJetpackConnectedSite;
}

public void setIsJetpackConnectedSite(boolean isJetpackConnectedSite) {
this.isJetpackConnectedSite = isJetpackConnectedSite;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class AnalyticsTrackerNosara extends Tracker {
private static final String WPCOM_USER = "dotcom_user";
private static final String IS_GUTENBERG_ENABLED = "gutenberg_enabled";
private static final String APP_SCHEME = "app_scheme";
private static final String PLAN_SHORT_NAME = "plan_name";

private final String mEventsPrefix;

Expand Down Expand Up @@ -550,6 +551,7 @@ public void refreshMetadata(AnalyticsMetadata metadata) {
properties.put(NUMBER_OF_BLOGS, metadata.getNumBlogs());
properties.put(WPCOM_USER, metadata.isWordPressComUser());
properties.put(APP_SCHEME, metadata.getAppScheme());
properties.put(PLAN_SHORT_NAME, metadata.getPlanShortName());
// Only add the editor information if it was set before.
// See: https://github.com/wordpress-mobile/WordPress-Android/pull/10300#discussion_r309145514
if (metadata.isGutenbergEnabledVariableSet()) {
Expand Down

0 comments on commit 3066fda

Please sign in to comment.