FUS: use the same action id in action and toolbar collectors

This commit is contained in:
Svetlana.Zemlyanskaya
2019-01-23 19:31:27 +01:00
parent 63adf0b9a4
commit 528b9bd554
2 changed files with 28 additions and 28 deletions
@@ -11,6 +11,7 @@ import com.intellij.internal.statistic.service.fus.collectors.FUSUsageContext;
import com.intellij.internal.statistic.utils.PluginInfo;
import com.intellij.internal.statistic.utils.PluginInfoDetectorKt;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionWithDelegate;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.components.PersistentStateComponent;
@@ -75,19 +76,36 @@ public class ActionsCollectorImpl extends ActionsCollector implements Persistent
data.addPlace(place);
}
final String key = isDevelopedByJB ? toReportedId(action) : DEFAULT_ID;
FUSCounterUsageLogger.logEvent(GROUP, key, data);
FUSCounterUsageLogger.logEvent(GROUP, toReportedId(info, action), data);
}
@NotNull
private static String toReportedId(@NotNull AnAction action) {
final String actionId = action.isGlobal() ? ActionManager.getInstance().getId(action) : null;
if (StringUtil.isEmpty(actionId)) {
return action.getClass().getName();
public static String toReportedId(@NotNull PluginInfo info, @NotNull AnAction action) {
String actionId = getActionId(info, action);
if (actionId != null) {
return actionId;
}
if (action instanceof ActionWithDelegate) {
final Object delegate = ((ActionWithDelegate)action).getDelegate();
final PluginInfo delegateInfo = PluginInfoDetectorKt.getPluginInfo(delegate.getClass());
actionId = delegateInfo.isDevelopedByJetBrains() ? delegate.getClass().getName() : DEFAULT_ID;
}
else {
actionId = action.getClass().getName();
}
return ConvertUsagesUtil.escapeDescriptorName(actionId);
}
@Nullable
private static String getActionId(@NotNull PluginInfo info, @NotNull AnAction action) {
if (!info.isDevelopedByJetBrains()) {
return DEFAULT_ID;
}
return action.isGlobal() ? ActionManager.getInstance().getId(action) : null;
}
private State myState = new State();
@Nullable
@@ -2,6 +2,7 @@
package com.intellij.internal.statistic.collectors.fus.ui.persistence;
import com.intellij.internal.statistic.beans.ConvertUsagesUtil;
import com.intellij.internal.statistic.collectors.fus.actions.persistence.ActionsCollectorImpl;
import com.intellij.internal.statistic.eventLog.FeatureUsageDataBuilder;
import com.intellij.internal.statistic.eventLog.FeatureUsageGroup;
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
@@ -9,8 +10,6 @@ import com.intellij.internal.statistic.service.fus.collectors.FUSCounterUsageLog
import com.intellij.internal.statistic.service.fus.collectors.FUSUsageContext;
import com.intellij.internal.statistic.utils.PluginInfo;
import com.intellij.internal.statistic.utils.PluginInfoDetectorKt;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionWithDelegate;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.components.*;
import com.intellij.util.xmlb.annotations.MapAnnotation;
@@ -31,8 +30,7 @@ import java.util.Map;
}
)
public class ToolbarClicksCollector implements PersistentStateComponent<ToolbarClicksCollector.ClicksState> {
private static final FeatureUsageGroup GROUP = new FeatureUsageGroup("toolbar", 1);
private static final String DEFAULT_ID = "third.party.action";
private static final FeatureUsageGroup GROUP = new FeatureUsageGroup("toolbar", 2);
public final static class ClicksState {
@Tag("counts")
@@ -53,27 +51,11 @@ public class ToolbarClicksCollector implements PersistentStateComponent<ToolbarC
public static void record(@NotNull AnAction action, String place) {
final PluginInfo info = PluginInfoDetectorKt.getPluginInfo(action.getClass());
final boolean isDevelopedByJB = info.isDevelopedByJetBrains();
final String key = isDevelopedByJB ? toReportedId(action) : DEFAULT_ID;
final FeatureUsageDataBuilder builder = new FeatureUsageDataBuilder().addPluginInfo(info);
if (isDevelopedByJB) {
if (info.isDevelopedByJetBrains()) {
builder.addPlace(place);
}
record(key, builder);
}
private static String toReportedId(@NotNull AnAction action) {
String id = ActionManager.getInstance().getId(action);
if (id == null) {
if (action instanceof ActionWithDelegate) {
id = ((ActionWithDelegate)action).getPresentableName();
} else {
id = action.getClass().getName();
}
}
return id;
record(ActionsCollectorImpl.toReportedId(info, action), builder);
}
public static void record(String actionId) {