Skip to content

Commit

Permalink
CCA: Ensure the duration of capture metrics is integer
Browse files Browse the repository at this point in the history
The value of a GA event is not allowed to be a floating number and the
event will be unexpectedly dropped causing the incorrectresults of
video capture metrics.
See: https://support.google.com/analytics/answer/1033068

This CL ensures that eventValue is an integer if presents in GA event,
and also returns integer when querying the duration from RecordTime.

(cherry picked from commit 90a31eb)

Bug: b:263926816
Test: Manually
Change-Id: I3e5379d6efc12499f8955ded54697b20509ad0d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4128178
Commit-Queue: Wei Lee <wtlee@chromium.org>
Reviewed-by: Chu-Hsuan Yang <chuhsuan@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1087718}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4153730
Commit-Queue: Shik Chen <shik@chromium.org>
Auto-Submit: Wei Lee <wtlee@chromium.org>
Reviewed-by: Shik Chen <shik@chromium.org>
Cr-Commit-Position: refs/branch-heads/5481@{#212}
Cr-Branched-From: 130f3e4-refs/heads/main@{#1084008}
  • Loading branch information
Wei Lee authored and Chromium LUCI CQ committed Jan 11, 2023
1 parent c63e76f commit 7e25b4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ abstract class RecordTimeBase {
* Returns the recorded duration in milliseconds.
*/
inMilliseconds(): number {
return this.totalDuration;
return Math.round(this.totalDuration);
}
}

Expand Down
12 changes: 8 additions & 4 deletions ash/webui/camera_app_ui/resources/js/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ async function sendEvent(
assignDimension(event, dimen);
}

if (event.eventValue !== undefined && !Number.isInteger(event.eventValue)) {
// Round the duration here since GA expects that the value is an
// integer. Reference:
// https://support.google.com/analytics/answer/1033068
event.eventValue = Math.round(event.eventValue);
}

await ready.wait();

// This value reflects the logging consent option in OS settings.
Expand Down Expand Up @@ -402,10 +409,7 @@ export function sendPerfEvent({event, duration, perfInfo = {}}: PerfEventParam):
eventCategory: 'perf',
eventAction: event,
eventLabel: facing,
// Round the duration here since GA expects that the value is an
// integer. Reference:
// https://support.google.com/analytics/answer/1033068
eventValue: Math.round(duration),
eventValue: duration,
},
new Map([
[MetricDimension.RESOLUTION, `${resolution}`],
Expand Down

0 comments on commit 7e25b4a

Please sign in to comment.