Skip to content

Commit 49637d3

Browse files
fix screen leave event bug
1 parent 1c31f76 commit 49637d3

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ afterEvaluate {
3939
from components.release
4040
groupId = 'com.github.metricalp'
4141
artifactId = 'android'
42-
version = '1.4'
42+
version = '1.5'
4343
}
4444
}
4545
}

library/src/main/java/com/metricalp/android/Metricalp.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,26 +152,28 @@ public static boolean screenViewEvent(String path, HashMap<String, String> event
152152
Metricalp instance = Metricalp.getInstance();
153153
String prevScreen = instance.getCurrentScreen();
154154

155-
if (path != null) {
156-
attrs.put("path", path);
155+
if(path == null) {
156+
path = "(not-set)";
157157
}
158158

159+
attrs.put("path", path);
160+
159161
HashMap<String, String> screenLeaveAttrs = new HashMap<>();
160162

161163
if (prevScreen != null) {
162164
screenLeaveAttrs.put("leave_from_path", prevScreen);
163165
screenLeaveAttrs.put("leave_from_duration", String.valueOf(new Date().getTime() - instance.getScreenDurationStartPoint()));
164166
}
165167

166-
instance.setCurrentScreen(null);
167-
instance.setScreenDurationStartPoint(new Date().getTime());
168-
169168
attrs.putAll(screenLeaveAttrs);
170169

171170
if (eventAttributes != null) {
172171
attrs.putAll(eventAttributes);
173172
}
174173

174+
instance.setCurrentScreen(attrs.get("path"));
175+
instance.setScreenDurationStartPoint(new Date().getTime());
176+
175177
return Metricalp.sendEvent(
176178
"screen_view",
177179
attrs,
@@ -243,7 +245,9 @@ public void asynchronousPostRequest(String url, String requestBody) {
243245
public void onFailure(Call call, IOException e) {}
244246

245247
@Override
246-
public void onResponse(Call call, Response response) {}
248+
public void onResponse(Call call, Response response) {
249+
response.close();
250+
}
247251
});
248252
}
249253
}

0 commit comments

Comments
 (0)