Skip to content

Commit 26eff92

Browse files
authored
Merge pull request #1068 from databuddy-analytics/codex/tracker-interactions
feat(tracker): collect interactions by default
2 parents 6527e6f + 3925d57 commit 26eff92

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎packages/tracker/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class Databuddy extends BaseTracker {
119119
}
120120
const scrollCleanup = initScrollDepthTracking(this);
121121
this.cleanupFns.push(scrollCleanup);
122-
if (this.options.trackInteractions) {
122+
if (this.options.trackInteractions !== false) {
123123
const interactionCleanup = initInteractionTracking(this);
124124
this.cleanupFns.push(interactionCleanup);
125125
}

‎packages/tracker/tests/interactions.spec.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,50 @@ const SLOW_NAVIGATIONS = [
604604
];
605605

606606
test.describe("interaction frustration signals", () => {
607+
async function rageClickUnresponsiveButton(page: Page) {
608+
await page.click("button", { clickCount: 3 });
609+
return page.evaluate(
610+
() => (window.__tracker as BaseTracker).rageClickCount
611+
);
612+
}
613+
614+
test("interaction tracking is on without any configuration", async ({
615+
page,
616+
}) => {
617+
await page.goto("/test");
618+
await page.evaluate(() => {
619+
document.body.innerHTML = `<button type="button" aria-label="pay">Pay</button>`;
620+
window.databuddyConfig = {
621+
clientId: "test-interactions-default",
622+
ignoreBotDetection: true,
623+
};
624+
});
625+
await page.addScriptTag({ url: "/dist/databuddy-debug.js" });
626+
await expect
627+
.poll(() => page.evaluate(() => Boolean(window.__tracker)))
628+
.toBeTruthy();
629+
expect(await rageClickUnresponsiveButton(page)).toBe(1);
630+
});
631+
632+
test('data-track-interactions="false" turns interaction tracking off', async ({
633+
page,
634+
}) => {
635+
await page.goto("/test");
636+
await page.evaluate(() => {
637+
document.body.innerHTML = `<button type="button" aria-label="pay">Pay</button>`;
638+
const script = document.createElement("script");
639+
script.src = "/dist/databuddy-debug.js";
640+
script.dataset.clientId = "test-interactions-opt-out";
641+
script.dataset.ignoreBotDetection = "true";
642+
script.dataset.trackInteractions = "false";
643+
document.head.append(script);
644+
});
645+
await expect
646+
.poll(() => page.evaluate(() => Boolean(window.__tracker)))
647+
.toBeTruthy();
648+
expect(await rageClickUnresponsiveButton(page)).toBe(0);
649+
});
650+
607651
for (const { name, markup, act } of ORDINARY_CLICKS) {
608652
test(`${name} is neither a rage nor a dead click`, async ({ page }) => {
609653
await loadFixture(page, markup);

0 commit comments

Comments
 (0)