Skip to content
Draft
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
16 changes: 16 additions & 0 deletions src/detector.impressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<div data-ts-resolved-bid=""></div>
`;
await import("./detector");

expect(events).toMatchObject([]);
});
30 changes: 15 additions & 15 deletions src/detector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Config, Entity, TopsortClient, Event as TopsortEvent } from "@topsort/sdk";

Check failure on line 1 in src/detector.ts

View workflow job for this annotation

GitHub Actions / Biome Lint

format

File content differs from formatting output
import { version } from "../package.json";
import { ProcessorResult, Queue } from "./queue";
import { truncateSet } from "./set";
Expand Down Expand Up @@ -249,27 +249,27 @@

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]");
Expand Down
Loading