From 21dc4d4808818cda667c5bb4af8342f87728e0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Wed, 9 Oct 2024 18:19:15 +0100 Subject: [PATCH 1/3] fix: don't account for empty attributes --- src/detector.impressions.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/detector.impressions.test.ts b/src/detector.impressions.test.ts index df8ec57..1143b03 100644 --- a/src/detector.impressions.test.ts +++ b/src/detector.impressions.test.ts @@ -34,3 +34,19 @@ test("check impresssions", async () => { }, ]); }); + +test("don\'t consider empty attributes", async () => { + window.TS = { + token: "token", + }; + const events: any[] = []; + window.addEventListener("topsort", (e) => { + events.push((e as any).detail); + }); + document.body.innerHTML = ` +
+ `; + await import("./detector"); + + expect(events).toMatchObject([]); +}); From 45ff175189b51009a8d14990b4325dfc9b5a22c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Wed, 9 Oct 2024 18:24:53 +0100 Subject: [PATCH 2/3] fix: lint --- src/detector.impressions.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detector.impressions.test.ts b/src/detector.impressions.test.ts index 1143b03..8a116b8 100644 --- a/src/detector.impressions.test.ts +++ b/src/detector.impressions.test.ts @@ -35,7 +35,7 @@ test("check impresssions", async () => { ]); }); -test("don\'t consider empty attributes", async () => { +test("don't consider empty attributes", async () => { window.TS = { token: "token", }; From 1c3f87453e0f87128899895e8084306e2cbe8ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Thu, 10 Oct 2024 13:14:36 +0100 Subject: [PATCH 3/3] chore: use `:not` selector --- src/detector.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/detector.ts b/src/detector.ts index d525d4b..e6edca4 100644 --- a/src/detector.ts +++ b/src/detector.ts @@ -249,27 +249,27 @@ function interactionHandler(event: Event): void { const intersectionObserver = !!window.IntersectionObserver ? new IntersectionObserver( - (entries) => { - for (const entry of entries) { - if (entry.isIntersecting) { - const node = entry.target; - if (node instanceof HTMLElement) { - logEvent(getEvent("Impression", node), node); - if (intersectionObserver) { - intersectionObserver.unobserve(node); - } + (entries) => { + for (const entry of entries) { + if (entry.isIntersecting) { + const node = entry.target; + if (node instanceof HTMLElement) { + logEvent(getEvent("Impression", node), node); + if (intersectionObserver) { + intersectionObserver.unobserve(node); } } } - }, - { - threshold: INTERSECTION_THRESHOLD, - }, - ) + } + }, + { + threshold: INTERSECTION_THRESHOLD, + }, + ) : undefined; const PRODUCT_SELECTOR = - "[data-ts-product],[data-ts-action],[data-ts-items],[data-ts-resolved-bid]"; + '[data-ts-product]:not([data-ts-product=""]),[data-ts-action]:not([data-ts-action=""]),[data-ts-items]:not([data-ts-items=""]),[data-ts-resolved-bid]:not([data-ts-resolved-bid=""])'; function addClickHandler(node: HTMLElement) { const clickables = node.querySelectorAll("[data-ts-clickable]");