Skip to content

Commit 710ad4b

Browse files
committed
finished implementation GAnalitics
1 parent 9ed5ebd commit 710ad4b

File tree

8 files changed

+70
-42
lines changed

8 files changed

+70
-42
lines changed

resources/messages/messages_ru.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ SettingsDialogToneMapFilterWhitePoint=Точка белого экспозици
8080
SettingsDialogAnisotropy=Анизатропная фильтрация
8181
SettingsDialogButtonOk=Применить
8282
SettingsDialogButtonCancel=Отменить
83+
SettingsDialogAnalytics=Google Аналитика
8384
SettingsDialogMessage=Для применения настроек необходим рестарт.
8485

8586
OtherSettingsDialogTitle=Остальные настройки

src/com/ss/editor/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class Messages {
9696
public static final String SETTINGS_DIALOG_BUTTON_OK;
9797
public static final String SETTINGS_DIALOG_BUTTON_CANCEL;
9898
public static final String SETTINGS_DIALOG_MESSAGE;
99+
public static final String SETTINGS_DIALOG_GOOGLE_ANALYTICS;
99100

100101
public static final String OTHER_SETTINGS_DIALOG_TITLE;
101102
public static final String OTHER_SETTINGS_DIALOG_CLASSPATH_FOLDER_LABEL;
@@ -384,6 +385,7 @@ public class Messages {
384385
SETTINGS_DIALOG_BUTTON_OK = bundle.getString("SettingsDialogButtonOk");
385386
SETTINGS_DIALOG_BUTTON_CANCEL = bundle.getString("SettingsDialogButtonCancel");
386387
SETTINGS_DIALOG_MESSAGE = bundle.getString("SettingsDialogMessage");
388+
SETTINGS_DIALOG_GOOGLE_ANALYTICS = bundle.getString("SettingsDialogAnalytics");
387389

388390
OTHER_SETTINGS_DIALOG_TITLE = bundle.getString("OtherSettingsDialogTitle");
389391
OTHER_SETTINGS_DIALOG_CLASSPATH_FOLDER_LABEL = bundle.getString("OtherSettingsDialogClasspathFolderLabel");

src/com/ss/editor/analytics/google/GAEvent.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ interface Action {
2323
interface Label {
2424
String THE_EDITOR_APP_WAS_CLOSED = "The editor application was closed";
2525
String THE_EDITOR_APP_WAS_LAUNCHED = "The editor application was launched";
26-
String THE_EDITOR_WAS_OPENED = "The editor was opened for editing a file";
27-
String THE_EDITOR_WAS_CLOSED = "The editor was closed";
28-
String THE_DIALOG_WAS_OPENED = "The dialog was opened";
29-
String THE_DIALOG_WAS_CLOSED = "The dialog was closed";
3026
String WORKING_ON_AN_EDITOR = "Working on an editor";
3127
String SHOWING_A_DIALOG = "Showing a dialog";
3228
}

src/com/ss/editor/analytics/google/GAnalytics.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.ss.editor.EditorThread;
77
import com.ss.editor.config.Config;
8+
import com.ss.editor.config.EditorConfig;
89

910
import org.apache.http.StatusLine;
1011
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -44,13 +45,9 @@ public class GAnalytics extends EditorThread {
4445
public static final String PARAM_TRACKING_ID = "tid";
4546
public static final String PARAM_CLIENT_ID = "cid";
4647
public static final String PARAM_HIT_TYPE = "t";
47-
public static final String PARAM_USER_ID = "uid";
48-
public static final String PARAM_USER_LANGUAGE = "ul";
49-
public static final String PARAM_APPLICATION_VERSION = "av";
5048
public static final String PARAM_EVENT_CATEGORY = "ec";
5149
public static final String PARAM_EVENT_ACTION = "ea";
5250
public static final String PARAM_EVENT_LABEL = "el";
53-
public static final String PARAM_EVENT_VALUE = "ev";
5451
public static final String PARAM_PAGE_VIEW_LOCATION = "dl";
5552
public static final String PARAM_PAGE_VIEW_TITLE = "dt";
5653
public static final String PARAM_PAGE_VIEW_PAGE = "dp";
@@ -63,11 +60,15 @@ public class GAnalytics extends EditorThread {
6360
public static final String PARAM_CUSTOM_DIMENSION = "cd";
6461

6562
public static final String FIELD_OS = PARAM_CUSTOM_DIMENSION + "1";
63+
public static final String FIELD_APP_VERSION = PARAM_CUSTOM_DIMENSION + "2";
64+
public static final String FIELD_LOCALE = PARAM_CUSTOM_DIMENSION + "3";
65+
public static final String FIELD_USER_ID = PARAM_CUSTOM_DIMENSION + "4";
6666

6767
public static final String PROP_ANALYTICS_HOST = "http://www.google-analytics.com/collect";
6868
public static final String PROP_TRACKING_ID = "UA-89459340-1";
6969
public static final String PROP_CLIENT_ID = "89459340";
7070

71+
private static final EditorConfig EDITOR_CONFIG = EditorConfig.getInstance();
7172
private static final GAnalytics INSTANCE = new GAnalytics();
7273

7374
public static GAnalytics getInstance() {
@@ -78,6 +79,7 @@ public static GAnalytics getInstance() {
7879
* Wait for sending max 2 sec.
7980
*/
8081
public static void waitForSend() {
82+
if (!EDITOR_CONFIG.isAnalytics()) return;
8183
final GAnalytics instance = getInstance();
8284
final AtomicInteger progressCount = instance.progressCount;
8385
if (progressCount.get() < 1) return;
@@ -91,7 +93,7 @@ public static void waitForSend() {
9193
* @param action the action.
9294
*/
9395
public static void sendEvent(@NotNull final String category, @NotNull final String action) {
94-
sendEvent(category, action, null, null);
96+
sendEvent(category, action, null);
9597
}
9698

9799
/**
@@ -102,25 +104,12 @@ public static void sendEvent(@NotNull final String category, @NotNull final Stri
102104
* @param label the label.
103105
*/
104106
public static void sendEvent(@NotNull final String category, @NotNull final String action, @Nullable final String label) {
105-
sendEvent(category, action, label, null);
106-
}
107-
108-
/**
109-
* Send an event.
110-
*
111-
* @param category the category.
112-
* @param action the action.
113-
* @param label the label.
114-
* @param value the value.
115-
*/
116-
public static void sendEvent(@NotNull final String category, @NotNull final String action, @Nullable final String label, @Nullable final String value) {
117107

118108
final Map<String, Object> parameters = new HashMap<>();
119109
parameters.put(PARAM_EVENT_CATEGORY, category);
120110
parameters.put(PARAM_EVENT_ACTION, action);
121111

122112
if (!isEmpty(label)) parameters.put(PARAM_EVENT_LABEL, label);
123-
if (!isEmpty(value)) parameters.put(PARAM_EVENT_VALUE, value);
124113

125114
send(HitType.EVENT, parameters);
126115
}
@@ -204,6 +193,7 @@ private static void send(final HitType hitType, final Map<String, Object> parame
204193
* @param parameters the parameters.
205194
*/
206195
private static void send(final Map<String, Object> parameters) {
196+
if (!EDITOR_CONFIG.isAnalytics()) return;
207197
getInstance().addTask(() -> doSend(parameters));
208198
}
209199

@@ -232,9 +222,9 @@ private static void doSend(final Map<String, Object> parameters) {
232222
parameters.put(PARAM_CLIENT_ID, PROP_CLIENT_ID);
233223

234224
if (!StringUtils.isEmpty(os)) parameters.put(FIELD_OS, os);
235-
if (!StringUtils.isEmpty(appVersion)) parameters.put(PARAM_APPLICATION_VERSION, appVersion);
236-
if (!StringUtils.isEmpty(language)) parameters.put(PARAM_USER_LANGUAGE, language);
237-
if (!StringUtils.isEmpty(userId)) parameters.put(PARAM_USER_ID, userId);
225+
if (!StringUtils.isEmpty(appVersion)) parameters.put(FIELD_APP_VERSION, appVersion);
226+
if (!StringUtils.isEmpty(language)) parameters.put(FIELD_LOCALE, language);
227+
if (!StringUtils.isEmpty(userId)) parameters.put(FIELD_USER_ID, userId);
238228

239229
final String stringParameters = buildParameters(parameters);
240230
final byte[] byteParameters = stringParameters.getBytes("UTF-8");
@@ -313,7 +303,7 @@ private void addTask(@NotNull final Runnable runnable) {
313303

314304
@Override
315305
public void run() {
316-
for (; ; ) {
306+
for (;;) {
317307

318308
Runnable next;
319309

src/com/ss/editor/ui/component/bar/action/OpenAssetAction.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ private void process() {
4949
}
5050

5151
GAnalytics.sendPageView(null, null, "/dialog/AssetChooseDialog");
52-
GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_OPENED,
53-
GAEvent.Label.THE_DIALOG_WAS_OPENED, "AssetChooseDialog");
52+
GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_OPENED, "AssetChooseDialog");
5453

5554
final EditorFXScene scene = JFX_APPLICATION.getScene();
5655
final File folder = chooser.showDialog(scene.getWindow());
5756

58-
GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_CLOSED,
59-
GAEvent.Label.THE_DIALOG_WAS_CLOSED, "AssetChooseDialog");
57+
GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_CLOSED, "AssetChooseDialog");
6058

6159
if (folder == null) return;
6260

src/com/ss/editor/ui/component/editor/impl/AbstractFileEditor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void openFile(@NotNull final Path file) {
236236
final EditorDescription description = getDescription();
237237

238238
GAnalytics.sendEvent(GAEvent.Category.EDITOR, GAEvent.Action.EDITOR_OPENED,
239-
GAEvent.Label.THE_EDITOR_WAS_OPENED, description.getEditorId() + ":" + getFileName());
239+
description.getEditorId() + "/" + getFileName());
240240
}
241241

242242
@NotNull
@@ -346,7 +346,7 @@ public void notifyClosed() {
346346
final EditorDescription description = getDescription();
347347

348348
GAnalytics.sendEvent(GAEvent.Category.EDITOR, GAEvent.Action.EDITOR_CLOSED,
349-
GAEvent.Label.THE_EDITOR_WAS_CLOSED, description.getEditorId() + ":" + getFileName());
349+
description.getEditorId() + "/" + getFileName());
350350

351351
GAnalytics.sendTiming(GAEvent.Category.EDITOR, GAEvent.Label.WORKING_ON_AN_EDITOR,
352352
seconds, description.getEditorId());

src/com/ss/editor/ui/dialog/EditorDialog.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ public void show(@NotNull final Window owner) {
106106
}
107107

108108
GAnalytics.sendPageView(null, null, "/dialog/" + getDialogId());
109-
GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_OPENED,
110-
GAEvent.Label.THE_DIALOG_WAS_OPENED, getDialogId());
109+
GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_OPENED, getDialogId());
111110
}
112111

113112
@NotNull
@@ -137,11 +136,8 @@ public void hide() {
137136
FX_EVENT_MANAGER.removeEventHandler(WindowChangeFocusEvent.EVENT_TYPE, hideEventHandler);
138137
}
139138

140-
GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_CLOSED,
141-
GAEvent.Label.THE_DIALOG_WAS_CLOSED, getDialogId());
142-
143-
GAnalytics.sendTiming(GAEvent.Category.DIALOG, GAEvent.Label.SHOWING_A_DIALOG,
144-
seconds, getDialogId());
139+
GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_CLOSED, getDialogId());
140+
GAnalytics.sendTiming(GAEvent.Category.DIALOG, GAEvent.Label.SHOWING_A_DIALOG, seconds, getDialogId());
145141
}
146142

147143
/**

src/com/ss/editor/ui/dialog/SettingsDialog.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class SettingsDialog extends EditorDialog {
5656
private static final Insets FIELD_OFFSET = new Insets(5, 20, 0, 0);
5757
private static final Insets ADD_REMOVE_BUTTON_OFFSET = new Insets(0, 0, 0, 2);
5858

59-
private static final Point DIALOG_SIZE = new Point(600, 340);
59+
private static final Point DIALOG_SIZE = new Point(600, 370);
6060

6161
private static final Array<Integer> ANISOTROPYCS = ArrayFactory.newArray(Integer.class);
6262

@@ -78,7 +78,7 @@ public class SettingsDialog extends EditorDialog {
7878
private Label messageLabel;
7979

8080
/**
81-
* The combobox with anisotropy levels.
81+
* The list with anisotropy levels.
8282
*/
8383
private ComboBox<Integer> anisotropyComboBox;
8484

@@ -117,6 +117,11 @@ public class SettingsDialog extends EditorDialog {
117117
*/
118118
private CheckBox decoratedCheckBox;
119119

120+
/**
121+
* The checkbox for enabling google analytics.
122+
*/
123+
private CheckBox googleAnalyticsCheckBox;
124+
120125
/**
121126
* Поле для отображения выбранной папки дополнительного classpath.
122127
*/
@@ -173,6 +178,7 @@ protected void createContent(@NotNull final VBox root) {
173178
createAnisotropyControl(root);
174179
createGammaCorrectionControl(root);
175180
createFXAAControl(root);
181+
createGoogleAnalyticsControl(root);
176182
createDecoratedControl(root);
177183
createToneMapFilterControl(root);
178184
createToneMapFilterWhitePointControl(root);
@@ -447,6 +453,31 @@ private void createDecoratedControl(final VBox root) {
447453
VBox.setMargin(decoratedContainer, FIELD_OFFSET);
448454
}
449455

456+
/**
457+
* Create the checkbox for configuring decorated windows.
458+
*/
459+
private void createGoogleAnalyticsControl(final VBox root) {
460+
461+
final HBox container = new HBox();
462+
container.setAlignment(Pos.CENTER_LEFT);
463+
464+
final Label label = new Label(Messages.SETTINGS_DIALOG_GOOGLE_ANALYTICS + ":");
465+
label.setId(CSSIds.SETTINGS_DIALOG_LABEL);
466+
467+
googleAnalyticsCheckBox = new CheckBox();
468+
googleAnalyticsCheckBox.setId(CSSIds.SETTINGS_DIALOG_FIELD);
469+
googleAnalyticsCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> validate());
470+
471+
FXUtils.addToPane(label, container);
472+
FXUtils.addToPane(googleAnalyticsCheckBox, container);
473+
FXUtils.addToPane(container, root);
474+
475+
FXUtils.addClassTo(label, CSSClasses.SPECIAL_FONT_14);
476+
FXUtils.addClassTo(googleAnalyticsCheckBox, CSSClasses.SPECIAL_FONT_14);
477+
478+
VBox.setMargin(container, FIELD_OFFSET);
479+
}
480+
450481
/**
451482
* Создание настройкид ля выбора анизатроной фильтрации.
452483
*/
@@ -533,6 +564,13 @@ private CheckBox getDecoratedCheckBox() {
533564
return decoratedCheckBox;
534565
}
535566

567+
/**
568+
* @return the checkbox for enabling google analytics.
569+
*/
570+
private CheckBox getGoogleAnalyticsCheckBox() {
571+
return googleAnalyticsCheckBox;
572+
}
573+
536574
/**
537575
* @return надпись с сообщением.
538576
*/
@@ -541,7 +579,7 @@ public Label getMessageLabel() {
541579
}
542580

543581
/**
544-
* Валидация изменений.
582+
* Validate changes.
545583
*/
546584
private void validate() {
547585
if (isIgnoreListeners()) return;
@@ -602,6 +640,9 @@ private void load() {
602640
final CheckBox decoratedCheckBox = getDecoratedCheckBox();
603641
decoratedCheckBox.setSelected(editorConfig.isDecorated());
604642

643+
final CheckBox googleAnalyticsCheckBox = getGoogleAnalyticsCheckBox();
644+
googleAnalyticsCheckBox.setSelected(editorConfig.isAnalytics());
645+
605646
final Vector3f toneMapFilterWhitePoint = editorConfig.getToneMapFilterWhitePoint();
606647

607648
final Spinner<Double> toneMapFilterWhitePointX = getToneMapFilterWhitePointX();
@@ -691,6 +732,9 @@ private void processOk() {
691732
final CheckBox decoratedCheckBox = getDecoratedCheckBox();
692733
final boolean decorated = decoratedCheckBox.isSelected();
693734

735+
final CheckBox googleAnalyticsCheckBox = getGoogleAnalyticsCheckBox();
736+
final boolean analytics = googleAnalyticsCheckBox.isSelected();
737+
694738
final float toneMapFilterWhitePointX = getToneMapFilterWhitePointX().getValue().floatValue();
695739
final float toneMapFilterWhitePointY = getToneMapFilterWhitePointY().getValue().floatValue();
696740
final float toneMapFilterWhitePointZ = getToneMapFilterWhitePointZ().getValue().floatValue();
@@ -711,6 +755,7 @@ private void processOk() {
711755
editorConfig.setAnisotropy(anisotropy);
712756
editorConfig.setFXAA(fxaa);
713757
editorConfig.setDecorated(decorated);
758+
editorConfig.setAnalytics(analytics);
714759
editorConfig.setGammaCorrection(gammaCorrection);
715760
editorConfig.setToneMapFilter(toneMapFilter);
716761
editorConfig.setToneMapFilterWhitePoint(toneMapFilterWhitePoint);

0 commit comments

Comments
 (0)