Skip to content

Commit 166b83b

Browse files
committed
readme
1 parent bfc37f9 commit 166b83b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

packages/tracker/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Tracker Script Package
2+
3+
Internal monorepo package for building, testing, and deploying the core analytics tracker script (`databuddy.js`).
4+
5+
**⚠️ Internal Use Only**: This package is not published to NPM for public consumption. It generates the static assets served via our CDN.
6+
7+
## Workflows
8+
9+
### 1. Development
10+
Run the build in watch mode while developing:
11+
```bash
12+
bun run dev
13+
```
14+
15+
### 2. Comparison
16+
Before deploying, verify how your local changes compare to the live production script:
17+
```bash
18+
bun run diff
19+
```
20+
This fetches the current script from `https://databuddy.b-cdn.net`, compares hashes, and highlights differences.
21+
22+
### 3. Deployment
23+
To deploy the built artifacts to Bunny.net (Production CDN):
24+
```bash
25+
bun run release
26+
```
27+
*Requires `BUNNY_STORAGE_ZONE_NAME` and `BUNNY_STORAGE_ACCESS_KEY` environment variables.*
28+
29+
## Project Structure
30+
31+
- **`src/core/`**: The backbone of the tracker (`BaseTracker`, `HttpClient`, `utils`).
32+
- **`src/plugins/`**: Modular feature extensions (Web Vitals, Errors, etc.).
33+
- **`src/index.ts`**: The main entry point that assembles the `databuddy.js` bundle.
34+
- **`build.ts`**: Bun build script configuration.
35+
- **`deploy.ts`**: Internal CLI for handling Bunny.net uploads.
36+
- **`compare-release.ts`**: Internal tool for auditing local vs. remote scripts.
37+
38+
## Adding New Features
39+
40+
### Plugin Architecture
41+
We use a plugin-based architecture to keep the core lightweight.
42+
43+
1. **Create Plugin**: Add a new file in `src/plugins/` (e.g., `my-feature.ts`).
44+
2. **Implement Logic**: Export an init function receiving `BaseTracker`.
45+
```typescript
46+
export function initMyFeature(tracker: BaseTracker) {
47+
if (tracker.isServer()) return;
48+
// ... add event listeners
49+
}
50+
```
51+
3. **Register**: Import and call it in `src/index.ts` based on configuration flags.
52+
53+
## Testing
54+
55+
- **Local Server**: `bun run serve` spins up a test page at `http://localhost:3000` to manually verify tracking.
56+
- **E2E Tests**: `bun run test:e2e` runs Playwright suites.

0 commit comments

Comments
 (0)