1515import com .intellij .openapi .application .ApplicationManager ;
1616import com .intellij .openapi .project .Project ;
1717import com .microsoft .azuretools .ijidea .ui .SurveyPopUpDialog ;
18+ import com .microsoft .azuretools .telemetrywrapper .EventType ;
19+ import com .microsoft .azuretools .telemetrywrapper .EventUtil ;
20+ import com .microsoft .azuretools .telemetrywrapper .Operation ;
21+ import com .microsoft .azuretools .telemetrywrapper .TelemetryManager ;
1822import com .microsoft .intellij .actions .QualtricsSurveyAction ;
1923import org .apache .commons .io .IOUtils ;
2024import org .joda .time .LocalDateTime ;
2630import java .io .FileReader ;
2731import java .io .IOException ;
2832import java .nio .charset .Charset ;
33+ import java .util .HashMap ;
34+ import java .util .Map ;
2935import java .util .concurrent .TimeUnit ;
3036
37+ import static com .microsoft .azuretools .telemetry .TelemetryConstants .SURVEY ;
38+ import static com .microsoft .azuretools .telemetry .TelemetryConstants .SYSTEM ;
39+
3140public enum CustomerSurveyHelper {
3241
3342 INSTANCE ;
@@ -39,8 +48,13 @@ public enum CustomerSurveyHelper {
3948
4049 private static final String PLUGIN_FOLDER_NAME = "AzureToolsForIntelliJ" ;
4150 private static final String SURVEY_CONFIG_FILE = "SurveyConfig.json" ;
51+ private static final String TELEMETRY_KEY_RESPONSE = "response" ;
52+ private static final String TELEMETRY_VALUE_NEVER_SHOW = "neverShowAgain" ;
53+ private static final String TELEMETRY_VALUE_PUT_OFF = "putOff" ;
54+ private static final String TELEMETRY_VALUE_ACCEPT = "accept" ;
4255
4356 private SurveyConfig surveyConfig ;
57+ private Operation operation ;
4458
4559 CustomerSurveyHelper () {
4660 loadConfiguration ();
@@ -53,6 +67,13 @@ public void showFeedbackNotification(Project project) {
5367 .subscribe (next -> {
5468 SurveyPopUpDialog dialog = new SurveyPopUpDialog (CustomerSurveyHelper .this , project );
5569 dialog .setVisible (true );
70+ synchronized (CustomerSurveyHelper .class ) {
71+ if (operation != null ) {
72+ operation .complete ();
73+ }
74+ operation = TelemetryManager .createOperation (SYSTEM , SURVEY );
75+ operation .start ();
76+ }
5677 });
5778 }
5879 }
@@ -64,16 +85,19 @@ public void takeSurvey() {
6485 surveyConfig .lastSurveyDate = LocalDateTime .now ();
6586 surveyConfig .nextSurveyDate = LocalDateTime .now ().plusDays (TAKE_SURVEY_DELAY_BY_DAY );
6687 saveConfiguration ();
88+ sendTelemetry (TELEMETRY_VALUE_ACCEPT );
6789 }
6890
6991 public void putOff () {
7092 surveyConfig .nextSurveyDate = LocalDateTime .now ().plusDays (PUT_OFF_DELAY_BY_DAY );
7193 saveConfiguration ();
94+ sendTelemetry (TELEMETRY_VALUE_PUT_OFF );
7295 }
7396
7497 public void neverShowAgain () {
7598 surveyConfig .isAcceptSurvey = false ;
7699 saveConfiguration ();
100+ sendTelemetry (TELEMETRY_VALUE_NEVER_SHOW );
77101 }
78102
79103 private boolean isAbleToPopUpSurvey () {
@@ -111,6 +135,16 @@ private File getConfigFile() {
111135 return new File (pluginFolder , SURVEY_CONFIG_FILE );
112136 }
113137
138+ private synchronized void sendTelemetry (String response ) {
139+ if (operation == null ) {
140+ return ;
141+ }
142+ Map <String , String > properties = new HashMap <>();
143+ properties .put (TELEMETRY_KEY_RESPONSE , response );
144+ EventUtil .logEvent (EventType .info , operation , properties );
145+ operation .complete ();
146+ }
147+
114148 static class SurveyConfig {
115149 @ JsonProperty ("surveyTimes" )
116150 private int surveyTimes = 0 ;
0 commit comments