Skip to content

Commit 424aaea

Browse files
authored
Add telemetry for pop up survey (#3383)
1 parent 0697d62 commit 424aaea

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/helpers/CustomerSurveyHelper.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
import com.intellij.openapi.application.ApplicationManager;
1616
import com.intellij.openapi.project.Project;
1717
import 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;
1822
import com.microsoft.intellij.actions.QualtricsSurveyAction;
1923
import org.apache.commons.io.IOUtils;
2024
import org.joda.time.LocalDateTime;
@@ -26,8 +30,13 @@
2630
import java.io.FileReader;
2731
import java.io.IOException;
2832
import java.nio.charset.Charset;
33+
import java.util.HashMap;
34+
import java.util.Map;
2935
import java.util.concurrent.TimeUnit;
3036

37+
import static com.microsoft.azuretools.telemetry.TelemetryConstants.SURVEY;
38+
import static com.microsoft.azuretools.telemetry.TelemetryConstants.SYSTEM;
39+
3140
public 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;

Utils/azuretools-core/src/com/microsoft/azuretools/telemetry/TelemetryConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class TelemetryConstants {
4747
public static final String VFS = "virtualFileSystem";
4848

4949
// operation value
50+
public static final String SURVEY = "survey";
5051
public static final String FEEDBACK = "feedback";
5152
public static final String AZURECODE_SAMPLES = "azure-code-samples";
5253
public static final String LIB_CONFIGURATION = "libraries-configuration";

0 commit comments

Comments
 (0)