// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.vcs.log.statistics;

import com.intellij.internal.statistic.service.fus.collectors.FUCounterUsageLogger;
import com.intellij.internal.statistic.service.fus.collectors.UsageDescriptorKeyValidator;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.vcs.log.ui.VcsLogInternalDataKeys;
import org.jetbrains.annotations.NotNull;

public class VcsLogUsageTriggerCollector {

  public static void triggerUsage(@NotNull AnActionEvent e, @NotNull Object action) {
    String name = action.getClass().getName();
    if (name.contains(".")) name = name.substring(name.lastIndexOf(".") + 1);
    triggerUsage(e, name);
  }

  public static void triggerUsage(@NotNull AnActionEvent e, @NotNull String text) {
    triggerUsage(text, e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI) != null);
  }

  public static void triggerUsage(@NotNull String text) {
    triggerUsage(text, "");
  }

  public static void triggerUsage(@NotNull String text, boolean isFromHistory) {
    triggerUsage(text, isFromHistory ? "history." : "log.");
  }

  private static void triggerUsage(@NotNull String text, @NotNull String prefix) {
    String feature = prefix + UsageDescriptorKeyValidator.ensureProperKey(text);
    FUCounterUsageLogger.getInstance().logEvent("vcs.log.trigger", feature);
  }
}

@@ -176,16 +176,82 @@
 stics;%0A%0A
+import com.intellij.internal.statistic.eventLog.FeatureUsageData;%0A
 import c
@@ -1253,17 +1253,16 @@
 tory
-.
 %22 : %22log
 .%22);
@@ -1257,17 +1257,16 @@
 %22 : %22log
-.
 %22);%0A  %7D%0A
@@ -1339,22 +1339,23 @@
  String 
-prefix
+context
 ) %7B%0A    
@@ -1374,17 +1374,8 @@
 re =
- prefix +
  Usa
@@ -1496,16 +1496,68 @@
  feature
+, new FeatureUsageData().addData(%22context%22, context)
 );%0A  %7D%0A%7D

move context information from feature name to the data