Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging lcp target #607

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.7.47",
"version": "0.7.48",
"npmClient": "yarn",
"useWorkspaces": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "clarity",
"private": true,
"version": "0.7.47",
"version": "0.7.48",
"repository": "https://github.com/microsoft/clarity.git",
"author": "Sarvesh Nagpal <[email protected]>",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/clarity-decode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-decode",
"version": "0.7.47",
"version": "0.7.48",
"description": "An analytics library that uses web page interactions to generate aggregated insights",
"author": "Microsoft Corp.",
"license": "MIT",
Expand All @@ -26,7 +26,7 @@
"url": "https://github.com/Microsoft/clarity/issues"
},
"dependencies": {
"clarity-js": "^0.7.47"
"clarity-js": "^0.7.48"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/clarity-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-devtools",
"version": "0.7.47",
"version": "0.7.48",
"private": true,
"description": "Adds Clarity debugging support to browser devtools",
"author": "Microsoft Corp.",
Expand All @@ -24,9 +24,9 @@
"url": "https://github.com/Microsoft/clarity/issues"
},
"dependencies": {
"clarity-decode": "^0.7.47",
"clarity-js": "^0.7.47",
"clarity-visualize": "^0.7.47"
"clarity-decode": "^0.7.48",
"clarity-js": "^0.7.48",
"clarity-visualize": "^0.7.48"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/clarity-devtools/static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"manifest_version": 2,
"name": "Microsoft Clarity Developer Tools",
"description": "Clarity helps you understand how users are interacting with your website.",
"version": "0.7.47",
"version_name": "0.7.47",
"version": "0.7.48",
"version_name": "0.7.48",
"minimum_chrome_version": "50",
"devtools_page": "devtools.html",
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-js",
"version": "0.7.47",
"version": "0.7.48",
"description": "An analytics library that uses web page interactions to generate aggregated insights",
"author": "Microsoft Corp.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-js/src/core/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let version = "0.7.47";
let version = "0.7.48";
export default version;
9 changes: 8 additions & 1 deletion packages/clarity-js/src/data/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as variable from "@src/data/variable";
import * as extract from "@src/data/extract";
import { queue, track } from "./upload";

export default function(event: Event): void {
export default function(event: Event, target?: number): void {
let t = time();
let tokens: Token[] = [t, event];
switch (event) {
Expand Down Expand Up @@ -84,6 +84,13 @@ export default function(event: Event): void {
queue(tokens, false);
}
break;
case Event.LargestPaintTarget:
if(target){
// Log the id of the largest paint element
tokens.push(target);
queue(tokens, false);
}
break;
case Event.Dimension:
let dimensionKeys = Object.keys(dimension.updates);
if (dimensionKeys.length > 0) {
Expand Down
6 changes: 6 additions & 0 deletions packages/clarity-js/src/data/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export function max(metric: Metric, value: number): void {
}
}

export function logTarget(event: Event, target: number): void {
if(event == Event.LargestPaintTarget){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triple ===

encode(Event.LargestPaintTarget, target);
}
}

export function compute(): void {
encode(Event.Metric);
}
Expand Down
8 changes: 7 additions & 1 deletion packages/clarity-js/src/performance/observer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Code, Constant, Dimension, Metric, Severity } from "@clarity-types/data";
import { Code, Constant, Dimension, Event, Metric, Severity } from "@clarity-types/data";
import config from "@src/core/config";
import { bind } from "@src/core/event";
import measure from "@src/core/measure";
Expand All @@ -7,6 +7,8 @@ import * as dimension from "@src/data/dimension";
import * as metric from "@src/data/metric";
import * as internal from "@src/diagnostic/internal";
import * as navigation from "@src/performance/navigation";
import * as dom from "@src/layout/dom";


let observer: PerformanceObserver;
const types: string[] = [Constant.Navigation, Constant.Resource, Constant.LongTask, Constant.FID, Constant.CLS, Constant.LCP, Constant.PerformanceEventTiming];
Expand Down Expand Up @@ -81,6 +83,10 @@ function process(entries: PerformanceEntryList): void {
break;
case Constant.LCP:
if (visible) { metric.max(Metric.LargestPaint, entry.startTime); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to only log targetNode if it is visible? not sure why we log the metric when visible, but the rest of it regardless

const targetNode = dom.get((entry as any).element)?.id
if(targetNode){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, space between if and (

metric.logTarget(Event.LargestPaintTarget, targetNode)
}
break;
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/clarity-js/types/data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export const enum Event {
Snapshot = 43,
Animation = 44,
StyleSheetAdoption = 45,
StyleSheetUpdate = 46
StyleSheetUpdate = 46,
/**
* Metric related event data
*/
LargestPaintTarget = 47
}

export const enum Metric {
Expand Down
4 changes: 2 additions & 2 deletions packages/clarity-visualize/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-visualize",
"version": "0.7.47",
"version": "0.7.48",
"description": "An analytics library that uses web page interactions to generate aggregated insights",
"author": "Microsoft Corp.",
"license": "MIT",
Expand All @@ -27,7 +27,7 @@
"url": "https://github.com/Microsoft/clarity/issues"
},
"dependencies": {
"clarity-decode": "^0.7.47"
"clarity-decode": "^0.7.48"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down