diff --git a/packages/tracker/src/index.ts b/packages/tracker/src/index.ts index 1f6915238..fbfa95a0a 100644 --- a/packages/tracker/src/index.ts +++ b/packages/tracker/src/index.ts @@ -119,7 +119,7 @@ export class Databuddy extends BaseTracker { } const scrollCleanup = initScrollDepthTracking(this); this.cleanupFns.push(scrollCleanup); - if (this.options.trackInteractions) { + if (this.options.trackInteractions !== false) { const interactionCleanup = initInteractionTracking(this); this.cleanupFns.push(interactionCleanup); } diff --git a/packages/tracker/tests/interactions.spec.ts b/packages/tracker/tests/interactions.spec.ts index 5963fbf90..e080d24c0 100644 --- a/packages/tracker/tests/interactions.spec.ts +++ b/packages/tracker/tests/interactions.spec.ts @@ -604,6 +604,50 @@ const SLOW_NAVIGATIONS = [ ]; test.describe("interaction frustration signals", () => { + async function rageClickUnresponsiveButton(page: Page) { + await page.click("button", { clickCount: 3 }); + return page.evaluate( + () => (window.__tracker as BaseTracker).rageClickCount + ); + } + + test("interaction tracking is on without any configuration", async ({ + page, + }) => { + await page.goto("/test"); + await page.evaluate(() => { + document.body.innerHTML = ``; + window.databuddyConfig = { + clientId: "test-interactions-default", + ignoreBotDetection: true, + }; + }); + await page.addScriptTag({ url: "/dist/databuddy-debug.js" }); + await expect + .poll(() => page.evaluate(() => Boolean(window.__tracker))) + .toBeTruthy(); + expect(await rageClickUnresponsiveButton(page)).toBe(1); + }); + + test('data-track-interactions="false" turns interaction tracking off', async ({ + page, + }) => { + await page.goto("/test"); + await page.evaluate(() => { + document.body.innerHTML = ``; + const script = document.createElement("script"); + script.src = "/dist/databuddy-debug.js"; + script.dataset.clientId = "test-interactions-opt-out"; + script.dataset.ignoreBotDetection = "true"; + script.dataset.trackInteractions = "false"; + document.head.append(script); + }); + await expect + .poll(() => page.evaluate(() => Boolean(window.__tracker))) + .toBeTruthy(); + expect(await rageClickUnresponsiveButton(page)).toBe(0); + }); + for (const { name, markup, act } of ORDINARY_CLICKS) { test(`${name} is neither a rage nor a dead click`, async ({ page }) => { await loadFixture(page, markup);