address PR comments

This commit is contained in:
Zoe Yang
2024-04-24 16:33:47 -07:00
parent 1520061bd8
commit 9e0abccf0c
4 changed files with 20 additions and 20 deletions

View File

@@ -69,14 +69,12 @@ export function decode(tokens: Data.Token[]): InteractionEvent {
};
return { time, event, data: submitData };
case Data.Event.Scroll:
const topHash = tokens.length > 5 ? (tokens[5] as string).split(Data.Constant.Dot) : null;
const bottomHash = tokens.length > 6 ? (tokens[6] as string).split(Data.Constant.Dot) : null;
let scrollData: Interaction.ScrollData = {
target: tokens[2] as number,
x: tokens[3] as number,
y: tokens[4] as number,
top: topHash?.length > 1 ? topHash[1] : null,
bottom: bottomHash?.length > 1 ? bottomHash[1] : null,
top: tokens.length > 5 ? (tokens[5] as string) : null,
bottom: tokens.length > 6 ? (tokens[6] as string) : null
};
return { time, event, data: scrollData };
case Data.Event.Timeline:

View File

@@ -119,15 +119,15 @@ export default async function (type: Event, ts: number = null): Promise<void> {
let sTarget = metadata(entry.data.target as Node, entry.event);
const top = metadata(entry.data.top as Node, entry.event);
const bottom = metadata(entry.data.bottom as Node, entry.event);
const cTopHash = top.hash ? top.hash.join(Constant.Dot) : Constant.Empty;
const cBottomHash = bottom.hash ? bottom.hash.join(Constant.Dot) : Constant.Empty;
const sTopHash = top.hash ? top.hash.join(Constant.Dot) : Constant.Empty;
const sBottomHash = bottom.hash ? bottom.hash.join(Constant.Dot) : Constant.Empty;
if (sTarget.id > 0) {
tokens = [entry.time, entry.event];
tokens.push(sTarget.id);
tokens.push(entry.data.x);
tokens.push(entry.data.y);
tokens.push(cTopHash);
tokens.push(cBottomHash);
tokens.push(sTopHash);
tokens.push(sBottomHash);
queue(tokens);
baseline.track(entry.event, entry.data.x, entry.data.y, entry.time);
}

View File

@@ -1,4 +1,4 @@
import { Dimension, Event } from "@clarity-types/data";
import { Constant, Dimension, Event } from "@clarity-types/data";
import { ScrollState, Setting } from "@clarity-types/interaction";
import { bind } from "@src/core/event";
import { schedule } from "@src/core/task";
@@ -10,8 +10,8 @@ import encode from "./encode";
import * as dimension from "@src/data/dimension";
export let state: ScrollState[] = [];
let initTopNode: Node;
let initBottomNode: Node;
let initialTop: Node;
let initialBottom: Node;
let timeout: number = null;
export function start(): void {
@@ -55,8 +55,8 @@ function recompute(event: UIEvent = null): void {
// We don't send any scroll events if this is the first event and the current position is top (0,0)
if ((event === null && x === 0 && y === 0) || (x === null || y === null)) {
initTopNode = top;
initBottomNode = bottom;
initialTop = top;
initialBottom = bottom;
return;
}
@@ -101,11 +101,13 @@ function similar(last: ScrollState, current: ScrollState): boolean {
}
export function compute(): void {
if (initTopNode || initBottomNode) {
const sTopTarget = metadata(initTopNode, null);
const sBottomTarget = metadata(initBottomNode, null);
dimension.log(Dimension.InitialTop, sTopTarget?.hash?.[1]);
dimension.log(Dimension.InitialBottom, sBottomTarget?.hash?.[1]);
if (initialTop) {
const top = metadata(initialTop, null);
dimension.log(Dimension.InitialScrollTop, top?.hash?.join(Constant.Dot));
}
if (initialBottom) {
const bottom = metadata(initialBottom, null);
dimension.log(Dimension.InitialScrollBottom, bottom?.hash?.join(Constant.Dot));
}
}

View File

@@ -146,8 +146,8 @@ export const enum Dimension {
Dob = 28,
CookieVersion = 29,
DeviceFamily = 30, // Allows iOS SDK to override the DeviceFamily value parsed from UserAgent.
InitialTop = 31,
InitialBottom = 32
InitialScrollTop = 31,
InitialScrollBottom = 32
}
export const enum Check {