From c6d00612ef2a1d9dac156736cd35029bde06625d Mon Sep 17 00:00:00 2001 From: ArtursKadikis Date: Tue, 7 Mar 2023 20:12:56 +0200 Subject: [PATCH] Fixed a bug where view duration was reported in ms and not s. (#36) --- CHANGELOG.md | 1 + app-java/src/main/java/ly/count/java/demo/Sample.java | 8 ++++++++ .../java/ly/count/sdk/java/internal/ViewImpl.java | 11 +++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 382de034b..4b986a2ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ * ! Minor breaking change ! The module override functionality is being removed from the SDK. * ! Minor breaking change ! It is not possible to set the logging tag anymore. * Fixed a bug where the wrong platform field value was being sent in the view request. +* Fixed a bug where view duration was reported in ms and not s. * Updated JSON library version from "20180813" to "20230227". 20.11.5 diff --git a/app-java/src/main/java/ly/count/java/demo/Sample.java b/app-java/src/main/java/ly/count/java/demo/Sample.java index 29504c9e8..9173f9258 100755 --- a/app-java/src/main/java/ly/count/java/demo/Sample.java +++ b/app-java/src/main/java/ly/count/java/demo/Sample.java @@ -148,6 +148,8 @@ public void LogHappened(String logMessage, Config.LoggingLevel logLevel) { System.out.println("9) Set user profile"); System.out.println("10) Set user custom profile"); System.out.println("11) Record an exception"); + System.out.println("12) Start a view called 'example_view'"); + System.out.println("13) End a view called 'example_view'"); System.out.println("0) Exit "); @@ -189,6 +191,12 @@ public void LogHappened(String logMessage, Config.LoggingLevel logLevel) { case 11: recordCrash(); break; + case 12: + Countly.session().view("example_view").start(true); + break; + case 13: + Countly.session().view("example_view").stop(false); + break; default: break; } diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ViewImpl.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ViewImpl.java index 73d45f4b1..ccd3c1060 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ViewImpl.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ViewImpl.java @@ -49,9 +49,7 @@ public void start(boolean firstView) { this.started = true; this.firstView = firstView; - start = (EventImpl) session.event(EVENT).addSegments(NAME, this.name, - VISIT, VISIT_VALUE, - SEGMENT, Device.dev.getOS()); + start = (EventImpl) session.event(EVENT).addSegments(NAME, this.name, VISIT, VISIT_VALUE, SEGMENT, Device.dev.getOS()); if (firstView) { start.addSegment(START, START_VALUE); @@ -79,10 +77,11 @@ public void stop(boolean lastView) { } ended = true; - EventImpl event = (EventImpl) session.event(EVENT).addSegments(NAME, this.name, - SEGMENT, SEGMENT_VALUE); + EventImpl event = (EventImpl) session.event(EVENT).addSegments(NAME, this.name, SEGMENT, SEGMENT_VALUE); - event.setDuration(Device.dev.uniqueTimestamp() - start.getTimestamp()); + long viewDurationSeconds = (Device.dev.uniqueTimestamp() - start.getTimestamp()) / 1000; + + event.setDuration(viewDurationSeconds); if (lastView) { event.addSegment(EXIT, EXIT_VALUE);