Skip to content

Commit

Permalink
some metrics fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlbo committed Mar 26, 2024
1 parent daca8ef commit d5e85a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 1 addition & 3 deletions app/src/main/java/com/vk/libvideo/VideoTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
Expand All @@ -11,7 +10,6 @@
import com.vk.media.player.PlayerTypes;
import com.vk.navigation.NavigatorKeys;
import com.vk.statistic.Statistic;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.hooks.other.Preferences;
Expand Down Expand Up @@ -333,6 +331,6 @@ public void sendMetrics(String event) throws JSONException {
jsonObject.put("position_sec", 0);
jsonObject.put("cur_quality", "auto");

Metrics.trackEvents(jsonObject);
Metrics.trackEvents(jsonObject, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.vk.navigation.NavigatorKeys;
import com.vtosters.lite.data.Analytics;
import kotlin.jvm.b.Functions2;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.hooks.other.Preferences;
Expand Down Expand Up @@ -185,7 +184,7 @@ private void makeMetricsRequest(MusicPlaybackParams musicPlaybackParams, String
}
}

Metrics.trackEvents(event);
Metrics.trackEvents(event, true);
}

private Analytics.l a(MusicPlaybackParams musicPlaybackParams, String str) {
Expand Down
22 changes: 17 additions & 5 deletions app/src/main/java/ru/vtosters/lite/utils/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,25 @@
public class Metrics {
private static JSONArray events = new JSONArray();

public static void trackEvents(JSONObject object) {
if (!NetworkUtils.isNetworkConnected()) {
events.put(object);
} else if (shouldSaveUserTraffic() || events.length() > 0) {
trackEventList(object);
public static void trackEvents(JSONObject object, boolean isMusic) {
if (NetworkUtils.isNetworkConnected()) {
handleNetworkConnected(object, isMusic);
} else {
handleNetworkDisconnected(object, isMusic);
}
}

private static void handleNetworkConnected(JSONObject object, boolean isMusic) {
if (isMusic || shouldSaveUserTraffic() || events.length() > 0) {
trackEventsImmediately(object);
} else {
trackEventList(object);
}
}

private static void handleNetworkDisconnected(JSONObject object, boolean isMusic) {
if (!isMusic) {
events.put(object);
}
}

Expand Down

0 comments on commit d5e85a7

Please sign in to comment.