Skip to content
Merged
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
42 changes: 42 additions & 0 deletions ANALYTICS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Website adoption measurement

Property: **Suites Website**, `449431617`. Measurement ID: `G-G7FJBNFPJJ`.
Analytics loads only for Netlify production builds.

## Adoption events

| Event | Trigger | Interpretation |
| --- | --- | --- |
| `installation_copy` | A successful code-block copy containing a Suites install command | Intent to install Suites |
| `test_example_copy` | A successful code-block copy containing a `TestBed.solitary()` or `TestBed.sociable()` example on a framework guide | Intent to try a framework example |
| `search_result_click` | Selecting a search result | Search helped the reader find a document |

Copy events send the page path and, for framework examples, the framework name. They never send copied code. They observe Expressive Code's successful clipboard feedback, so a failed copy does not count. Copies do not prove an installation or a passing test.

Search opens, search results, and empty searches remain diagnostic events. The existing `ads_conversion_PAGE_VIEW_1` measures page-view conversions and must not be interpreted as adoption.

## GA property setup

After reviewing and deploying the branch:

1. In **Admin > Data display > Events**, create or mark `installation_copy` and `test_example_copy` as key events. Use **Once per session** for each. GA allows registering event names before their first occurrence.
2. Under **Custom definitions**, create an event-scoped dimension named **Framework**, with event parameter `framework`.
3. Keep `search_result_click` available for search reporting. Do not treat search activity alone as installation intent.

Property setup is separate from the website code. Check the GA interface for the registered definitions before treating setup as complete. Key-event registration applies to future events, not historical data.

## Validate without polluting production data

In a local build with `CONTEXT=production`, block Google tag network requests and stub `window.gtag` to capture calls. Copy a Suites install command and a framework test example. Each successful copy should emit the corresponding event; unrelated code and failed copies should emit neither event. A normal preview build must load no Google tag.

Run `pnpm test`, `pnpm check`, and `CONTEXT=production pnpm build` for automated checks.

## Compare launch performance

Use the property's **Asia/Jerusalem** timezone and complete days of equal length. Exclude the November 5, 2026 launch day when comparing the launch windows. Filter `hostName` to `suites.dev` to remove local and other-domain traffic. Normalize trailing slashes when grouping page paths.

Report `aocr.org` traffic separately: it recorded zero engagement time in the initial launch comparison and should not be assumed to represent readers. Keep the unfiltered totals available alongside any filtered analysis.

Review users, sessions, docs readership, Google organic sessions, adoption key events, search-result clicks, and 404 page titles. The initial sample is small; changes do not establish that the redesign caused growth.

See Google's documentation for [key-event registration](https://support.google.com/analytics/answer/13128484) and [counting methods](https://support.google.com/analytics/answer/13366706).
5 changes: 5 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ from = "/docs/adapters/*"
to = "/docs/get-started/"
status = 301

[[redirects]]
from = "/docs/fundamentals/adapters"
to = "/docs/get-started/installation/#supported-libraries-adapters"
status = 301

[[redirects]]
from = "/docs/guides/adapters/inversifyjs"
to = "/docs/guides/inversify/"
Expand Down
21 changes: 21 additions & 0 deletions src/components/islands/AdoptionAnalytics.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script>
import { copiedCodeEvent } from '@/lib/adoptionAnalytics.js';
import { trackEvent } from '@/utils/analytics';

// Expressive Code adds this feedback only after a successful clipboard copy.
// Observing feedback avoids counting failed clipboard attempts as adoption.
const observer = new MutationObserver(records => {
for (const record of records) {
for (const node of record.addedNodes) {
if (!(node instanceof HTMLElement) || !node.matches('.feedback')) continue;
const button = node.parentElement?.matches('.expressive-code .copy')
? node.parentElement.querySelector<HTMLButtonElement>('button[data-code]')
: null;
if (!button) continue;
const event = copiedCodeEvent(window.location.pathname, button.dataset.code ?? '');
if (event) trackEvent(event.name, event.params);
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
</script>
2 changes: 2 additions & 0 deletions src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import DocsHeader from '@/components/site/Header.astro';
import MarketingHeader from '@/components/site/MarketingHeader.astro';
import Footer from '@/components/site/Footer.astro';
import GoogleAnalytics from '@/components/islands/GoogleAnalytics.astro';
import AdoptionAnalytics from '@/components/islands/AdoptionAnalytics.astro';
import '@/styles/globals.css';
import { DEFAULT_SOCIAL_IMAGE, SITE_DESCRIPTION, SITE_NAME, SITE_URL, pageTitle } from '@/config/seo';

Expand Down Expand Up @@ -219,5 +220,6 @@ const graph = canonicalUrl && !preventIndexing ? {
<slot />
</main>
{showFooter && <Footer />}
{process.env.CONTEXT === 'production' && <AdoptionAnalytics />}
</body>
</html>
21 changes: 21 additions & 0 deletions src/lib/adoptionAnalytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Classify successful code copies without sending the code itself to GA.
* These events measure intent to try Suites, not a completed installation.
* @param {string} pathname
* @param {string} code
*/
export function copiedCodeEvent(pathname, code) {
// Expressive Code stores newlines as DEL characters in data-code.
code = code.replace(/\x7f/g, '\n');
const route = pathname.replace(/^\/docs\/v\d+\//, '/docs/').replace(/\/$/, '');
if (!route.startsWith('/docs/')) return;

if (/^\s*(?:pnpm\s+add|npm\s+(?:install|i)|yarn\s+add)\b[^\n]*@suites\/unit(?=\s|$)/m.test(code)) {
return { name: 'installation_copy', params: { page_path: pathname } };
}

const framework = route.match(/^\/docs\/guides\/(nestjs|inversify|injectionjs)$/)?.[1];
if (framework && /\bTestBed\s*\.\s*(?:solitary|sociable)\s*\(/.test(code)) {
return { name: 'test_example_copy', params: { page_path: pathname, framework } };
}
}
44 changes: 44 additions & 0 deletions tests/adoption-analytics.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { copiedCodeEvent } from '../src/lib/adoptionAnalytics.js';

test('recognizes install commands for all documented package managers', () => {
for (const command of ['pnpm add -D', 'npm install --save-dev', 'npm i -D', 'yarn add --dev']) {
assert.deepEqual(copiedCodeEvent('/docs/get-started/installation/', `${command} @suites/unit @suites/di.nestjs`), {
name: 'installation_copy', params: { page_path: '/docs/get-started/installation/' },
});
}
});

test('does not mistake imports, runner installation, or prose for Suites installation', () => {
for (const code of ["import { TestBed } from '@suites/unit';", 'pnpm add -D vitest', 'Use pnpm add -D @suites/unit', 'pnpm add -D @suites/unit-other']) {
assert.equal(copiedCodeEvent('/docs/get-started/installation/', code), undefined);
}
});

test('handles rendered code blocks whose line breaks are encoded by Expressive Code', () => {
assert.equal(copiedCodeEvent('/docs/get-started/installation/', '# Install Suites\x7fpnpm add -D @suites/unit')?.name, 'installation_copy');
assert.equal(copiedCodeEvent('/docs/guides/nestjs/', 'await TestBed\x7f.solitary(UserService).compile();')?.name, 'test_example_copy');
});

test('recognizes full framework test examples and sends no copied content', () => {
for (const framework of ['nestjs', 'inversify', 'injectionjs']) {
const pathname = `/docs/guides/${framework}/`;
assert.deepEqual(copiedCodeEvent(pathname, 'const { unit } = await TestBed\n .solitary(UserService).compile();'), {
name: 'test_example_copy', params: { page_path: pathname, framework },
});
assert.equal(copiedCodeEvent(pathname, 'class UserService {}'), undefined);
}
});

test('supports sociable examples and versioned docs without tracking homepage copies', () => {
const code = 'await TestBed.sociable(UserService).expose(Formatter).compile();';
assert.equal(copiedCodeEvent('/docs/v4/guides/nestjs/', code)?.name, 'test_example_copy');
assert.equal(copiedCodeEvent('/', code), undefined);
assert.equal(copiedCodeEvent('/docs/api-reference/testbed-sociable/', code), undefined);
});

test('ignores framework setup and unrelated copies', () => {
assert.equal(copiedCodeEvent('/docs/guides/nestjs/', 'pnpm exec jest'), undefined);
assert.equal(copiedCodeEvent('/docs/get-started/installation/', '{ "experimentalDecorators": true }'), undefined);
});
Loading