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

fix: don't account for empty attributes #292

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
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