Skip to content

feat(tracking): add CF Worker tracking pixel endpoint with KV schema#58

Merged
AojdevStudio merged 1 commit intomainfrom
feature/gdrive-19-cf-worker-tracking-pixel
Mar 28, 2026
Merged

feat(tracking): add CF Worker tracking pixel endpoint with KV schema#58
AojdevStudio merged 1 commit intomainfrom
feature/gdrive-19-cf-worker-tracking-pixel

Conversation

@AojdevStudio
Copy link
Copy Markdown
Owner

@AojdevStudio AojdevStudio commented Mar 28, 2026

Summary

Implements GDRIVE-19: CF Worker tracking pixel endpoint + KV schema.

The core tracking implementation was already landed in main (commit c4be21f), but lacked a dedicated kv-schema.ts module. This PR extracts the KV schema definitions into a canonical module and updates tracking.ts to import from it.

Changes

  • New: src/server/kv-schema.ts — canonical KV schema definitions
    • summaryKey(campaignId) helper for consistent key construction
    • TRACKING_TTL_SECONDS (90 days) constant
    • KVLike, RecipientTracking, TrackingSummary interfaces
    • Prefix constants for campaign listing: tracking:summary:
  • Updated: src/server/tracking.ts — imports from kv-schema.ts

Acceptance Criteria

  • AC-1: GET /track/:campaignId/:recipientId/pixel.gif returns 1x1 transparent GIF with Content-Type: image/gif and Cache-Control: no-store
  • AC-2: Each pixel request writes/updates open event in KV with timestamp, count, and metadata (totalOpens, uniqueOpens, firstOpenedAt, lastOpenedAt)
  • AC-3: KV key schema tracking:summary:{campaignId} supports efficient prefix-based listing by campaignId

Test Results

  • 6/6 tracking unit tests pass
  • 50/50 test suites pass (568 tests)
  • TypeScript type-check: clean

Closes #52

Summary by CodeRabbit

  • Refactor
    • Reorganized tracking system configuration and schemas for improved code maintainability and centralized key/value storage definitions.

- Extract KV schema types and key helpers to src/server/kv-schema.ts
  (summaryKey(), TRACKING_TTL_SECONDS, KVLike, RecipientTracking, TrackingSummary)
- Update tracking.ts to import from kv-schema.ts (single source of truth)
- KV key pattern: tracking:summary:{campaignId} supports prefix-based listing
- handleTrackingRequest: GET /track/:campaignId/:recipientId/pixel.gif
  returns 1x1 transparent GIF + writes open event to KV (90-day TTL)
- getTrackingData: queries campaign open events by campaignId
- All 6 unit tests pass; type-check clean

Closes #52
Resolves GDRIVE-19
@linear
Copy link
Copy Markdown

linear Bot commented Mar 28, 2026

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 28, 2026

📝 Walkthrough

Walkthrough

This PR extracts KV schema definitions (constants, key builder, TTL, and TypeScript interfaces) from tracking.ts into a new kv-schema.ts module, establishing a centralized source of truth for the campaign open tracking storage structure used by Cloudflare Workers.

Changes

Cohort / File(s) Summary
KV Schema Module
src/server/kv-schema.ts
New module defining tracking KV namespace: TRACKING_PREFIX, SUMMARY_PREFIX, summaryKey() helper, 90-day TTL constant, and interfaces for RecipientTracking (open count + timestamps), TrackingSummary (campaign data), and KVLike (minimal KV storage interface).
Tracking Refactor
src/server/tracking.ts
Removed inline KV type definitions (KVLike, RecipientTracking, TrackingSummary) and TTL constant; now re-exports from kv-schema.ts. Replaced hardcoded key string with summaryKey() helper in write and read paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • Issue #53: This PR provides the centralized KV schema and summaryKey() / getTrackingData() infrastructure needed to implement campaign open tracking queries in downstream tracking data retrieval features.

Poem

🐰 Hop, hop! Schemas now unite—
One source of truth shines bright,
No duplication in sight,
Keys and types align just right,
Tracking's foundation now in flight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The PR title references the KV schema extraction and updates to tracking.ts, but does not mention the primary feature being implemented: the CF Worker tracking pixel endpoint and open event recording functionality. Clarify the title to emphasize the tracking pixel endpoint and KV event recording, e.g., 'feat(tracking): implement CF Worker tracking pixel endpoint with KV schema'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed All three acceptance criteria from #52 are met: the endpoint returns 1x1 transparent GIF with correct headers, KV records open events with timestamps and metadata, and the schema supports prefix-based listing via the tracking:summary: pattern.
Out of Scope Changes check ✅ Passed All changes are directly within scope: kv-schema.ts defines the canonical KV schema and TTL constant, and tracking.ts refactors to use centralized definitions. No unrelated changes to click tracking, unsubscribe, analytics UI, or other out-of-scope areas are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/gdrive-19-cf-worker-tracking-pixel

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

📊 Type Coverage Report

Type Coverage: 98.61%

This PR's TypeScript type coverage analysis is complete.
Check the full report in the workflow artifacts.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
gdrive-mcp 1e549a0 Commit Preview URL

Branch Preview URL
Mar 28 2026, 07:45 PM

@github-actions
Copy link
Copy Markdown

🔒 Security Scan Summary

Generated on: Sat Mar 28 19:46:36 UTC 2026
Commit: 31beb84

Scan Results

  • SAST Analysis: success
  • Dependency Scan: success
  • Secret Scan: success
  • Docker Security Scan: success
  • License Scan: success

Summary

  • Total scans: 5
  • Critical issues: 0
  • Overall status: ✅ PASS

Recommendations

  1. Review all failed scans and address critical issues
  2. Update dependencies with known vulnerabilities
  3. Ensure no secrets are committed to the repository
  4. Follow Docker security best practices
  5. Review license compliance for all dependencies

Security report generated by Claude Code

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/server/kv-schema.ts (1)

64-79: Consider adding an explicit schema version field for future migrations.

The comment mentions "Schema version: 1" but the interface doesn't include a version field in the stored data. If the schema evolves, having an explicit version field would simplify migration logic.

💡 Optional: Add schemaVersion field
 export interface TrackingSummary {
+  /** Schema version for migration support. */
+  schemaVersion?: 1;
   /** Campaign identifier matching the URL segment. */
   campaignId: string;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/server/kv-schema.ts` around lines 64 - 79, Add an explicit schemaVersion
field to the TrackingSummary interface and ensure all write/read paths set and
respect it: update the TrackingSummary definition to include schemaVersion:
number (initialize to 1 for existing/new records), update any
constructors/creators that build TrackingSummary objects (e.g., where
TrackingSummary is constructed/returned) to set schemaVersion = 1, and adjust
persistence/read logic to tolerate missing schemaVersion for backward
compatibility (treat missing as 1) so future migrations can branch on
TrackingSummary.schemaVersion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/server/kv-schema.ts`:
- Around line 64-79: Add an explicit schemaVersion field to the TrackingSummary
interface and ensure all write/read paths set and respect it: update the
TrackingSummary definition to include schemaVersion: number (initialize to 1 for
existing/new records), update any constructors/creators that build
TrackingSummary objects (e.g., where TrackingSummary is constructed/returned) to
set schemaVersion = 1, and adjust persistence/read logic to tolerate missing
schemaVersion for backward compatibility (treat missing as 1) so future
migrations can branch on TrackingSummary.schemaVersion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7100dd4a-6709-411a-ba9d-53eb520bef08

📥 Commits

Reviewing files that changed from the base of the PR and between b8a24aa and 1e549a0.

📒 Files selected for processing (2)
  • src/server/kv-schema.ts
  • src/server/tracking.ts

@github-actions
Copy link
Copy Markdown

Performance Comparison Report

Operation Performance

Operation Baseline Avg Current Avg Change Status
listFiles 95.0ms 44.7ms -52.9% 🚀 IMPROVEMENT
readFile 180.0ms 96.5ms -46.4% 🚀 IMPROVEMENT
createFile 250.0ms 146.6ms -41.4% 🚀 IMPROVEMENT
cacheOperation 45.0ms 57.8ms 28.4% ❌ REGRESSION

Memory Usage

  • Baseline: 45.2 MB
  • Current: 4.41 MB
  • Change: -90.2%

Summary

  • 🚀 Improvements: 3
  • ❌ Regressions: 1

⚠️ Performance regressions detected! Please review the changes.


Performance report generated by Claude Code

@AojdevStudio AojdevStudio merged commit 9cb5ad0 into main Mar 28, 2026
28 checks passed
@AojdevStudio AojdevStudio deleted the feature/gdrive-19-cf-worker-tracking-pixel branch March 28, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CF Worker tracking pixel endpoint + KV schema

1 participant