Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
case RequestCodes.CREATE_SITE:
if (data != null) {
int newSiteLocalID = data.getIntExtra(SitePickerActivity.KEY_LOCAL_ID, -1);
SiteUtils.enableBlockEditor(mDispatcher, mSiteStore, newSiteLocalID);
SiteUtils.enableBlockEditorOnSiteCreation(mDispatcher, mSiteStore, newSiteLocalID);
// Mark the site to show the GB popup at first editor run
SiteModel newSiteModel = mSiteStore.getSiteByLocalId(newSiteLocalID);
if (newSiteModel != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ public void onClick(View v) {
// Enable the block editor on sites created on mobile
if (data != null) {
int newSiteLocalID = data.getIntExtra(SitePickerActivity.KEY_LOCAL_ID, -1);
SiteUtils.enableBlockEditor(mDispatcher, mSiteStore, newSiteLocalID);
SiteUtils.enableBlockEditorOnSiteCreation(mDispatcher, mSiteStore, newSiteLocalID);
// Mark the site to show the GB popup at first editor run
SiteModel newSiteModel = mSiteStore.getSiteByLocalId(newSiteLocalID);
if (newSiteModel != null) {
Expand Down Expand Up @@ -1156,6 +1156,9 @@ public void onSiteEditorsChanged(OnSiteEditorsChanged event) {
return;
}

// Need to update the user property about GB enabled on any of the sites
AnalyticsUtils.refreshMetadata(mAccountStore, mSiteStore);

// "Reload" selected site from the db
// It would be better if the OnSiteChanged provided the list of changed sites.
if (getSelectedSite() == null && mSiteStore.hasSite()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
import org.wordpress.android.util.WPPermissionUtils;
import org.wordpress.android.util.WPUrlUtils;
import org.wordpress.android.util.analytics.AnalyticsUtils;
import org.wordpress.android.util.analytics.AnalyticsUtils.BlockEditorEnabledSource;
import org.wordpress.android.util.helpers.MediaFile;
import org.wordpress.android.util.helpers.MediaGallery;
import org.wordpress.android.util.helpers.MediaGalleryImageSpan;
Expand Down Expand Up @@ -1550,10 +1551,16 @@ private void showGutenbergInformativeDialog() {
}

private void setGutenbergEnabledIfNeeded() {
if ((TextUtils.isEmpty(mSite.getMobileEditor()) && !mIsNewPost)
|| AppPrefs.shouldShowGutenbergInfoPopup(mSite.getUrl())) {
boolean showPopup = AppPrefs.shouldShowGutenbergInfoPopup(mSite.getUrl());

if (TextUtils.isEmpty(mSite.getMobileEditor()) && !mIsNewPost) {
SiteUtils.enableBlockEditor(mDispatcher, mSite);
AnalyticsUtils.trackWithSiteDetails(Stat.EDITOR_GUTENBERG_ENABLED, mSite);
AnalyticsUtils.trackWithSiteDetails(Stat.EDITOR_GUTENBERG_ENABLED, mSite,
BlockEditorEnabledSource.ON_BLOCK_POST_OPENING.asPropertyMap());
showPopup = true;
}

if (showPopup) {
showGutenbergInformativeDialog();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.wordpress.android.util.WPActivityUtils;
import org.wordpress.android.util.WPPrefUtils;
import org.wordpress.android.util.analytics.AnalyticsUtils;
import org.wordpress.android.util.analytics.AnalyticsUtils.BlockEditorEnabledSource;
import org.wordpress.android.widgets.WPSnackbar;

import java.util.HashMap;
Expand Down Expand Up @@ -742,7 +743,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
AnalyticsUtils.trackWithSiteDetails(
((Boolean) newValue) ? Stat.EDITOR_GUTENBERG_ENABLED : Stat.EDITOR_GUTENBERG_DISABLED,
mSite);
mSite, BlockEditorEnabledSource.VIA_SITE_SETTINGS.asPropertyMap());
// we need to refresh metadata as gutenberg_enabled is now part of the user data
AnalyticsUtils.refreshMetadata(mAccountStore, mSiteStore);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.wordpress.android.fluxc.generated.SiteActionBuilder;
import org.wordpress.android.fluxc.model.PostFormatModel;
import org.wordpress.android.fluxc.model.SiteModel;
import org.wordpress.android.fluxc.store.AccountStore;
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.fluxc.store.SiteStore.OnPostFormatsChanged;
import org.wordpress.android.fluxc.store.SiteStore.OnSiteEditorsChanged;
Expand All @@ -31,6 +32,7 @@
import org.wordpress.android.util.LocaleManager;
import org.wordpress.android.util.SiteUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.analytics.AnalyticsUtils;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -171,6 +173,7 @@ public interface SiteSettingsListener {

@Inject SiteStore mSiteStore;
@Inject Dispatcher mDispatcher;
@Inject AccountStore mAccountStore;

protected SiteSettingsInterface(Context host, SiteModel site, SiteSettingsListener listener) {
((WordPress) host.getApplicationContext()).component().inject(this);
Expand Down Expand Up @@ -1137,6 +1140,9 @@ public void onSiteEditorsChanged(OnSiteEditorsChanged event) {
return;
}

// Need to update the user property about GB enabled on any of the sites
AnalyticsUtils.refreshMetadata(mAccountStore, mSiteStore);

notifyUpdatedOnUiThread();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.wordpress.android.analytics.AnalyticsTracker.Stat;
import org.wordpress.android.fluxc.Dispatcher;
import org.wordpress.android.fluxc.generated.SiteActionBuilder;
import org.wordpress.android.fluxc.model.SiteModel;
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.fluxc.store.SiteStore.DesignateMobileEditorPayload;
import org.wordpress.android.ui.plans.PlansConstants;
import org.wordpress.android.ui.prefs.AppPrefs;
import org.wordpress.android.util.analytics.AnalyticsUtils;
import org.wordpress.android.util.analytics.AnalyticsUtils.BlockEditorEnabledSource;
import org.wordpress.android.util.helpers.Version;

import java.util.ArrayList;
Expand Down Expand Up @@ -68,10 +71,13 @@ public void run() {
}).start();
}

public static boolean enableBlockEditor(Dispatcher dispatcher, SiteStore siteStore, int siteLocalSiteID) {
public static boolean enableBlockEditorOnSiteCreation(Dispatcher dispatcher, SiteStore siteStore,
int siteLocalSiteID) {
SiteModel newSiteModel = siteStore.getSiteByLocalId(siteLocalSiteID);
if (newSiteModel != null) {
enableBlockEditor(dispatcher, newSiteModel);
enableBlockEditor(dispatcher, newSiteModel);
AnalyticsUtils.trackWithSiteDetails(Stat.EDITOR_GUTENBERG_ENABLED, newSiteModel,
BlockEditorEnabledSource.ON_SITE_CREATION.asPropertyMap());
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.models.ReaderPost;
import org.wordpress.android.ui.posts.PostListViewLayoutType;
import org.wordpress.android.ui.prefs.AppPrefs;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.FluxCUtils;
import org.wordpress.android.util.ImageUtils;
Expand Down Expand Up @@ -70,6 +69,18 @@ public class AnalyticsUtils {

public static final String HAS_GUTENBERG_BLOCKS_KEY = "has_gutenberg_blocks";

public enum BlockEditorEnabledSource {
VIA_SITE_SETTINGS,
ON_SITE_CREATION,
ON_BLOCK_POST_OPENING;

public Map<String, Object> asPropertyMap() {
Map<String, Object> properties = new HashMap<>();
properties.put("source", name().toLowerCase(Locale.ROOT));
return properties;
}
}

public static void updateAnalyticsPreference(Context ctx,
Dispatcher mDispatcher,
AccountStore mAccountStore,
Expand Down Expand Up @@ -105,15 +116,10 @@ public static void refreshMetadata(AccountStore accountStore, SiteStore siteStor
metadata.setNumBlogs(siteStore.getSitesCount());
metadata.setUsername(accountStore.getAccount().getUserName());
metadata.setEmail(accountStore.getAccount().getEmail());

int siteLocalId = AppPrefs.getSelectedSite();
if (siteLocalId != -1) {
// Site previously selected, use it
SiteModel selectedSite = siteStore.getSiteByLocalId(siteLocalId);
// If saved site exist, then add info
if (selectedSite != null) {
metadata.setGutenbergEnabled(
SiteUtils.isBlockEditorDefaultForNewPost(selectedSite));
for (SiteModel currentSite : siteStore.getSites()) {
if (SiteUtils.GB_EDITOR_NAME.equals(currentSite.getMobileEditor())) {
metadata.setGutenbergEnabled(true);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class AnalyticsMetadata {
private String mUsername = "";
private String mEmail = "";
private boolean mIsGutenbergEnabled;
private boolean mIsGutenbergEnabledVariableSet;

public AnalyticsMetadata() {
}
Expand Down Expand Up @@ -73,7 +74,12 @@ public boolean isGutenbergEnabled() {
return mIsGutenbergEnabled;
}

public boolean isGutenbergEnabledVariableSet() {
return mIsGutenbergEnabledVariableSet;
}

public void setGutenbergEnabled(boolean gutenbergEnabled) {
this.mIsGutenbergEnabled = gutenbergEnabled;
this.mIsGutenbergEnabledVariableSet = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,11 @@ public void refreshMetadata(AnalyticsMetadata metadata) {
properties.put(JETPACK_USER, metadata.isJetpackUser());
properties.put(NUMBER_OF_BLOGS, metadata.getNumBlogs());
properties.put(WPCOM_USER, metadata.isWordPressComUser());
properties.put(IS_GUTENBERG_ENABLED, metadata.isGutenbergEnabled());
// 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()) {
properties.put(IS_GUTENBERG_ENABLED, metadata.isGutenbergEnabled());
}
mNosaraClient.registerUserProperties(properties);
} catch (JSONException e) {
AppLog.e(AppLog.T.UTILS, e);
Expand Down