-
Notifications
You must be signed in to change notification settings - Fork 202
/
CustomEventTracker.java
305 lines (250 loc) · 13.5 KB
/
CustomEventTracker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package com.photoeditorsdk.android.app;
import android.os.Parcel;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import java.util.List;
import ly.img.android.PESDK;
import ly.img.android.sdk.models.config.interfaces.StickerConfigInterface;
import ly.img.android.sdk.utils.Trace;
import ly.img.sdk.android.annotations.StateEvents;
import ly.img.android.PESDKEvents;
import ly.img.android.sdk.models.state.ColorAdjustmentSettings;
import ly.img.android.sdk.models.state.EditorMenuState;
import ly.img.android.sdk.models.state.FilterSettings;
import ly.img.android.sdk.models.state.FocusSettings;
import ly.img.android.sdk.models.state.LayerListSettings;
import ly.img.android.sdk.models.state.TransformSettings;
import ly.img.android.sdk.models.state.layer.BrushLayerSettings;
import ly.img.android.sdk.models.state.layer.StickerLayerSettings;
import ly.img.android.sdk.models.state.manager.EventTracker;
import ly.img.sdk.android.annotations.OnEvent;
@StateEvents
public class CustomEventTracker extends EventTracker {
private Tracker googleAnalyticsTracker;
private String trackerId;
public CustomEventTracker(String trackerId) {
init(trackerId);
}
private void init(String trackerId) {
this.trackerId = trackerId;
GoogleAnalytics analytics = GoogleAnalytics.getInstance(PESDK.getAppContext());
googleAnalyticsTracker = analytics.newTracker(trackerId);
}
@OnEvent(PESDKEvents.EditorMenuState_TOOL_STACK_CHANGED)
protected void changeToolView(EditorMenuState menuState) {
googleAnalyticsTracker.setScreenName(menuState.getCurrentTool().getName());
googleAnalyticsTracker.send(new HitBuilders.ScreenViewBuilder().build());
}
@OnEvent(value = PESDKEvents.EditorMenuState_CANCEL_AND_LEAVE, ignoreReverts = true)
protected void onLeaveToolWithCancel(EditorMenuState menuState) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("menu action")
.setLabel(menuState.getCurrentTool().getName())
.setAction("cancel");
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.EditorMenuState_ACCEPT_AND_LEAVE, ignoreReverts = true)
protected void onLeaveToolWithAccept(EditorMenuState menuState) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("menu action")
.setLabel(menuState.getCurrentTool().getName())
.setAction("accept");
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.ColorAdjustmentSettings_CONTRAST, ignoreReverts = true, triggerDelay = 1000)
protected void onColorAdjustmentChangeContrast(ColorAdjustmentSettings colorAdjustmentSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("change color adjustment")
.setLabel("contrast")
.setAction("changed")
.setValue(Math.round(colorAdjustmentSettings.getContrast() * 100));
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.ColorAdjustmentSettings_BRIGHTNESS, ignoreReverts = true, triggerDelay = 1000)
protected void onColorAdjustmentChangeBrightness(ColorAdjustmentSettings colorAdjustmentSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("change color adjustment")
.setLabel("brightness")
.setAction("changed")
.setValue(Math.round(colorAdjustmentSettings.getBrightness() * 100));
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.ColorAdjustmentSettings_SATURATION, ignoreReverts = true, triggerDelay = 1000)
protected void onColorAdjustmentChangeSaturation(ColorAdjustmentSettings colorAdjustmentSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("change color adjustment")
.setLabel("saturation")
.setAction("changed")
.setValue(Math.round(colorAdjustmentSettings.getSaturation() * 100));
googleAnalyticsTracker.send(builder.build());
Trace.out("Test", "Saturation", Math.round(colorAdjustmentSettings.getSaturation() * 100));
}
@OnEvent(value = PESDKEvents.BrushLayerSettings_COLOR, ignoreReverts = true, triggerDelay = 1000)
protected void onBrushColorChange(BrushLayerSettings brushLayerSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("change brush")
.setLabel("color")
.setAction("changed")
.setValue(brushLayerSettings.getBrushColor());
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.BrushLayerSettings_HARDNESS, ignoreReverts = true, triggerDelay = 1000)
protected void onBrushHardnessChange(BrushLayerSettings brushLayerSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("change brush")
.setLabel("hardness")
.setAction("changed")
.setValue(Math.round(brushLayerSettings.getBrushHardness() * 100));
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.BrushLayerSettings_SIZE, ignoreReverts = true, triggerDelay = 1000)
protected void onBrushSizeChange(BrushLayerSettings brushLayerSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("change brush")
.setLabel("size")
.setAction("changed")
.setValue(Math.round(brushLayerSettings.getBrushSize()));
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.TransformSettings_ASPECT, ignoreReverts = true, triggerDelay = 1000)
protected void onCropAspectChanged(TransformSettings cropSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("crop changed")
.setLabel("aspect")
.setAction("changed aspect to: "+cropSettings.getAspectConfig().getName());
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.FilterSettings_FILTER, ignoreReverts = true, triggerDelay = 1000)
protected void onFilterChanged(FilterSettings filterSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("filter changed")
.setLabel("filter: " + filterSettings.getFilter().getName())
.setAction("set fitler");
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.FilterSettings_INTENSITY, ignoreReverts = true, triggerDelay = 1000)
protected void onFilterIntensityChanged(FilterSettings filterSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("filter changed")
.setLabel("filter: " + filterSettings.getFilter().getName())
.setAction("changed intensity to: " + filterSettings.getIntensity());
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.FocusSettings_MODE, ignoreReverts = true, triggerDelay = 1000)
protected void onFocusTypeChanged(FocusSettings focusSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("focus changed")
.setLabel("focus: " + focusSettings.getFocusMode())
.setAction("set type");
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.FocusSettings_INTENSITY, ignoreReverts = true, triggerDelay = 1000)
protected void onFocusIntensityChanged(FocusSettings focusSettings) {
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory("focus changed")
.setLabel("focus: " + focusSettings.getFocusMode())
.setAction("set intensity")
.setValue(Math.round(focusSettings.getFocusIntensity() * 100));
googleAnalyticsTracker.send(builder.build());
}
@OnEvent(value = PESDKEvents.LayerListSettings_ADD_LAYER, ignoreReverts = true)
protected void onStickerAdd(LayerListSettings settings) {
List<LayerListSettings.LayerSettings> list = settings.getLayerSettingsList();
LayerListSettings.LayerSettings lastLayer = list.get(list.size() - 1);
if (lastLayer instanceof StickerLayerSettings) {
StickerConfigInterface stickerConfig = ((StickerLayerSettings) lastLayer).getStickerConfig();
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory(stickerConfig.getType() == StickerConfigInterface.STICKER_TYPE.TEXT ? "text": "sticker")
.setLabel(stickerConfig.getName())
.setAction("add sticker");
googleAnalyticsTracker.send(builder.build());
}
}
@OnEvent(value = PESDKEvents.LayerListSettings_REMOVE_LAYER, ignoreReverts = true)
protected void onStickerRemove(LayerListSettings settings) {
List<LayerListSettings.LayerSettings> list = settings.getLayerSettingsList();
LayerListSettings.LayerSettings lastLayer = list.get(list.size() - 1);
if (lastLayer instanceof StickerLayerSettings) {
StickerConfigInterface stickerConfig = ((StickerLayerSettings) lastLayer).getStickerConfig();
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory(stickerConfig.getType() == StickerConfigInterface.STICKER_TYPE.TEXT ? "text": "sticker")
.setLabel(stickerConfig.getName())
.setAction("remove sticker");
googleAnalyticsTracker.send(builder.build());
}
}
@SuppressWarnings("unused")
@OnEvent(value = PESDKEvents.StickerLayerSettings_FLIP_HORIZONTAL, ignoreReverts = true)
protected void onStickerFlipHorizontal(LayerListSettings settings) {
LayerListSettings.LayerSettings lastLayer = settings.getSelected();
if (lastLayer instanceof StickerLayerSettings) {
StickerConfigInterface stickerConfig = ((StickerLayerSettings) lastLayer).getStickerConfig();
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory(stickerConfig.getType() == StickerConfigInterface.STICKER_TYPE.TEXT ? "text": "sticker")
.setLabel(stickerConfig.getName())
.setAction("horizontal flip");
googleAnalyticsTracker.send(builder.build());
}
}
@OnEvent(value = PESDKEvents.StickerLayerSettings_FLIP_VERTICAL, ignoreReverts = true)
protected void onStickerFlipVertical(LayerListSettings settings) {
LayerListSettings.LayerSettings lastLayer = settings.getSelected();
if (lastLayer instanceof StickerLayerSettings) {
StickerConfigInterface stickerConfig = ((StickerLayerSettings) lastLayer).getStickerConfig();
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory(stickerConfig.getType() == StickerConfigInterface.STICKER_TYPE.TEXT ? "text": "sticker")
.setLabel(stickerConfig.getName())
.setAction("vertical flip");
googleAnalyticsTracker.send(builder.build());
}
}
@OnEvent(value = PESDKEvents.StickerLayerSettings_PLACEMENT_INVALID, ignoreReverts = true)
protected void onStickerPositionChange(LayerListSettings settings) {
LayerListSettings.LayerSettings lastLayer = settings.getSelected();
if (lastLayer instanceof StickerLayerSettings) {
StickerConfigInterface stickerConfig = ((StickerLayerSettings) lastLayer).getStickerConfig();
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory(stickerConfig.getType() == StickerConfigInterface.STICKER_TYPE.TEXT ? "text": "sticker")
.setLabel(stickerConfig.getName())
.setAction("position changed");
googleAnalyticsTracker.send(builder.build());
}
}
@OnEvent(value = PESDKEvents.LayerListSettings_BRING_TO_FRONT, ignoreReverts = true)
protected void onStickerToFront(LayerListSettings settings) {
LayerListSettings.LayerSettings lastLayer = settings.getSelected();
if (lastLayer instanceof StickerLayerSettings) {
StickerConfigInterface stickerConfig = ((StickerLayerSettings) lastLayer).getStickerConfig();
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
.setCategory(stickerConfig.getType() == StickerConfigInterface.STICKER_TYPE.TEXT ? "text": "sticker")
.setLabel(stickerConfig.getName())
.setAction("bring to front");
googleAnalyticsTracker.send(builder.build());
}
}
// Many more trackable events ..........
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeString(this.trackerId);
}
protected CustomEventTracker(Parcel in) {
super(in);
init(in.readString());
}
public static final Creator<CustomEventTracker> CREATOR = new Creator<CustomEventTracker>() {
@Override
public CustomEventTracker createFromParcel(Parcel source) {
return new CustomEventTracker(source);
}
@Override
public CustomEventTracker[] newArray(int size) {
return new CustomEventTracker[size];
}
};
}