Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(traffic): keep the tracking snippet inside its dialog (#1206)

Cihan5d99c5f8266f
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_snippet-code.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_snippet-code.test.tsx
new file mode 100644
index 000000000..4acf3b9c6
--- /dev/null
+++ b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_snippet-code.test.tsx
@@ -0,0 +1,57 @@
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { NextIntlClientProvider } from 'next-intl';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import messages from '../../../../../../messages/en.json';
+
+/** The tracking snippet's dialog (AT-001): the whole tag, wrapped in its box, and a copy button. */
+
+vi.mock('@/config/api', () => ({ getPublicApiBaseUrl: () => 'https://api.example.com' }));
+
+const { SnippetDialog } = await import('./_snippet-code');
+
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT =
+ true;
+
+let container: HTMLDivElement;
+let root: Root;
+const writeText = vi.fn();
+
+beforeEach(() => {
+ Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText } });
+ writeText.mockReset();
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+});
+
+afterEach(() => {
+ act(() => root.unmount());
+ container.remove();
+ document.body.innerHTML = '';
+});
+
+describe('SnippetDialog', () => {
+ it('shows the whole tag, wrapping in its box rather than widening the dialog, and copies it', async () => {
+ await act(async () => {
+ root.render(
+ <NextIntlClientProvider locale="en" messages={messages}>
+ <SnippetDialog trackingCode="t_abc123" open onOpenChange={() => {}} />
+ </NextIntlClientProvider>,
+ );
+ });
+ const tag = '<script src="https://api.example.com/t.js" data-t="t_abc123" defer></script>';
+ const pre = document.body.querySelector('pre')!;
+ expect(pre.textContent).toBe(tag);
+ // jsdom has no layout: what keeps it inside the dialog is the wrap and a
+ // block that may shrink below the tag's width (a grid item otherwise can't).
+ expect(pre.className).toContain('whitespace-pre-wrap');
+ expect(pre.closest('.min-w-0')?.parentElement?.className).toContain('min-w-0');
+
+ const copy = document.body.querySelector(
+ 'button[aria-label="Copy tracking script"]',
+ ) as HTMLElement;
+ await act(async () => copy.click());
+ expect(writeText).toHaveBeenCalledWith(tag);
+ });
+});
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_snippet-code.tsx b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_snippet-code.tsx
index a595190e1..d6707873f 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/traffic/_snippet-code.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/traffic/_snippet-code.tsx
@@ -15,7 +15,11 @@ function snippetTag(trackingCode?: string): string | null {
return `<script src="${apiUrl}/t.js" data-t="${trackingCode}" defer></script>`;
}
-/** Where the tag goes, the tag, and a copy button. */
+/**
+ * Where the tag goes, the tag, and a copy button. The tag wraps inside its
+ * box, and the block can shrink below the tag's width: in the dialog's grid
+ * it would otherwise widen the dialog past the screen.
+ */
function SnippetCode({ snippet }: { snippet: string }) {
const t = useTranslations('traffic');
const [copied, setCopied] = useState(false);
@@ -27,7 +31,7 @@ function SnippetCode({ snippet }: { snippet: string }) {
};
return (
- <div className="flex items-start gap-3">
+ <div className="flex min-w-0 items-start gap-3">
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground">
{t.rich('snippetDescription', {
@@ -35,7 +39,7 @@ function SnippetCode({ snippet }: { snippet: string }) {
code: (chunks) => <code className="text-[11px]">{chunks}</code>,
})}
</p>
- <pre className="mt-2 overflow-x-auto rounded-md bg-muted/50 px-3 py-2 font-mono text-[11px]">
+ <pre className="mt-2 rounded-md bg-muted/50 px-3 py-2 font-mono text-[11px] break-all whitespace-pre-wrap">
{snippet}
</pre>
</div>