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
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ export const BASIC_TRACKING_OPTIONS: TrackingOptionConfig[] = [
{
key: "trackInteractions",
title: "Interactions",
description: "Track button clicks and form submissions",
data: ["Element clicked", "Form submissions"],
description:
"See where visitors get stuck: rage clicks, dead clicks, and forms they abandon",
data: [
"Rage and dead clicks",
"Clicked element labels, never text",
"Form fields touched and submitted",
],
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
generateAgentPrompt,
generateNpmCode,
generateScriptTag,
generateVueCode,
} from "./code-generators";
import { RECOMMENDED_DEFAULTS } from "./tracking-defaults";

Expand Down Expand Up @@ -69,6 +70,53 @@ assert.ok(prompt.includes("## Common issues"));
expect(npm).not.toContain("trackSessions");
});

it("leaves current-runtime interactions to the default and writes an explicit opt-out", () => {
const off = { ...RECOMMENDED_DEFAULTS, trackInteractions: false };

expect(
generateScriptTag("example-client-id", RECOMMENDED_DEFAULTS)
).not.toContain("track-interactions");
expect(generateScriptTag("example-client-id", off)).toContain(
'data-track-interactions="false"'
);
expect(generateNpmCode("example-client-id", off)).toContain(
"trackInteractions={false}"
);
expect(
generateNpmCode("example-client-id", RECOMMENDED_DEFAULTS)
).not.toContain("trackInteractions");
expect(
generateVueCode("example-client-id", RECOMMENDED_DEFAULTS)
).not.toContain("track-interactions");
expect(generateVueCode("example-client-id", off)).toContain(
':track-interactions="false"'
);
});

it.each([
true,
false,
])("keeps explicit interactions=%s for immutable pinned bundles", (trackInteractions) => {
const versionedScript = {
filename: "databuddy.v1.js",
sriHash: "sha384-example",
version: 1,
};
const script = generateScriptTag(
"example-client-id",
{ ...RECOMMENDED_DEFAULTS, trackInteractions, samplingRate: 0.5 },
versionedScript
);

expect(script).toContain(`/${versionedScript.filename}"`);
expect(script).toContain(`integrity="${versionedScript.sriHash}"`);
expect(script).toContain(`data-track-interactions="${trackInteractions}"`);
expect(script).toContain('data-track-web-vitals="true"');
expect(script).toContain('data-sampling-rate="0.5"');
expect(script).not.toContain("data-enable-batching");
expect(script).not.toContain("data-track-attributes");
});

it("asks for optional install feedback without code or secrets, and only names real options", () => {
const prompt = generateAgentPrompt("example-client-id");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Page views and sessions are automatic. Turn on the rest based on what the codeba
| trackWebVitals | Always. Powers the Web Vitals page (LCP, CLS, INP, TTFB). |
| trackErrors | Always for apps with client-side JavaScript. Powers the Errors page. |
| trackOutgoingLinks | Marketing sites, docs, link-heavy pages. Records clicks that leave the site. |
| trackInteractions | Apps with buttons and forms worth counting without custom events. |
| trackInteractions | On by default (rage clicks, dead clicks, form drop-off). Set it to false only where the site owner does not want click analytics. |
| trackAttributes | When you add data-track attributes to elements instead of calling track(). |
| trackHashChanges | Single-page apps that route with the URL hash. |
| skipPatterns | Admin, internal, or preview routes that should never be recorded, e.g. ["/admin/**"]. |
Expand Down Expand Up @@ -343,6 +343,10 @@ export function generateScriptTag(

const dataAttrs = Object.entries(trackingOptions)
.filter(([key, value]) => {
// Pinned bundles can predate the default-on behavior.
if (versionedScript && key === "trackInteractions" && value === true) {
return true;
}
const actualDefault =
ACTUAL_LIBRARY_DEFAULTS[key as keyof TrackingOptions];
if (value === actualDefault) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const ACTUAL_LIBRARY_DEFAULTS: TrackingOptions = {

trackAttributes: false,
trackOutgoingLinks: false,
trackInteractions: false,
trackInteractions: true,

trackWebVitals: false,
trackErrors: false,
Expand Down
Loading