-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add /track/open
#2683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add /track/open
#2683
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
WalkthroughA new API endpoint for tracking "open" events via POST requests was implemented, featuring input validation, caching, click event recording, error handling, and CORS support including OPTIONS preflight handling. Corresponding integration tests were added to verify correct behavior, including response structure, error cases, and CORS compliance for both POST and OPTIONS requests. Changes
Estimated code review effortπ― 2 (Simple) | β±οΈ ~8 minutes Poem
Note β‘οΈ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. π Recent review detailsConfiguration used: CodeRabbit UI π Files selected for processing (1)
π§ Files skipped from review as they are similar to previous changes (1)
β¨ Finishing Touches
π§ͺ Generate unit tests
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. πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (2)
apps/web/app/(ee)/api/track/open/route.ts(1 hunks)apps/web/tests/tracks/track-open.test.ts(1 hunks)
β° Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
π Additional comments (14)
apps/web/app/(ee)/api/track/open/route.ts (9)
1-24: Well-structured imports and CORS configuration.The imports are well-organized and the CORS headers are properly configured for cross-origin requests. The wildcard origin (
*) is appropriate for a public tracking endpoint.
21-29: Schema definitions look good with proper validation.The Zod schemas provide good input validation with string trimming and proper response type checking.
38-47: Redis cache key generation and clickId logic is well implemented.The parallel cache retrieval using
mgetis efficient, and the clickId generation/reuse logic is sound. Usingnanoid(16)provides good uniqueness for click tracking.
49-65: Link retrieval and caching implementation is robust.The error handling for non-existent links is appropriate, and the asynchronous cache setting using
waitUntilis a good performance optimization.
67-72: Workspace validation is essential for security.Good security check to ensure links belong to a workspace before processing. This prevents tracking of orphaned or malicious links.
74-87: Click recording logic with proper rate limiting bypass.The conditional click recording only for new clickIds is efficient and prevents duplicate tracking. The
skipRatelimit: trueandshouldCacheClickId: trueparameters are appropriate for this tracking endpoint.
89-98: Response handling and error management is well implemented.The response schema validation ensures type safety, and the error handling with CORS headers is properly implemented.
100-105: OPTIONS handler correctly implements CORS preflight support.The OPTIONS handler properly returns a 204 status with CORS headers as required for preflight requests.
36-36: No action needed: VERCEL detection is correct and consistentThe check
process.env.VERCEL === "1"is used throughout the codebase (e.g. in apps/web/app/providers.tsx, all tracking routes, cron jobs, middleware, etc.) to distinguish Vercel deployments from local development. This aligns with Vercelβs built-inVERCELvariable (set to"1"at runtime), so the IP handling logic in apps/web/app/(ee)/api/track/open/route.ts is already correct.apps/web/tests/tracks/track-open.test.ts (5)
5-16: Helper function provides good response validation.The
expectValidClickResponsehelper function properly validates the response structure and status code.
22-35: Basic tracking test is well-structured.The test properly validates the core functionality of the
/track/openendpoint.
79-95: CORS OPTIONS test is comprehensive and correct.The test properly validates all expected CORS headers for the OPTIONS preflight request.
110-121: ClickId format validation is properly implemented.The regex validation ensures the clickId follows the expected 16-character alphanumeric format matching the
nanoid(16)implementation.
37-57: Fix endpoint path inconsistency in clickId reuse test.The test is checking clickId consistency between endpoints, but there's a path mismatch that could cause confusion.
const response1 = await http.post<{ clickId: string }>({ - path: "/track/click", + path: "/track/open", headers: E2E_TRACK_CLICK_HEADERS, body: { domain: E2E_LINK.domain, key: E2E_LINK.key, }, });If the intention is to test cross-endpoint clickId consistency, please add a comment explaining this behavior.
Likely an incorrect or invalid review comment.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
@CodeRabbit final review |
|
Tip For best results, initiate chat on the files or code changes. π§© Analysis chainI'll conduct a comprehensive final review of the π Script executed: Length of output: 7508 Let me examine the other tracking endpoints for consistency and check for any patterns that should be followed. π Script executed: Length of output: 5598 @steven-tey Here's my comprehensive final review of the β Overall Assessment: High Quality ImplementationThe implementation is well-structured, secure, and follows most of the established patterns in the codebase. The test coverage is comprehensive and the functionality is solid. π Key Strengths
π§ Minor Consistency IssuesFor better alignment with existing tracking endpoints, consider these improvements:
π― Implementation Highlights
π Final VerdictThis is a solid, production-ready implementation. The minor consistency issues mentioned above are optional improvements that don't affect functionality. The code demonstrates good understanding of the existing patterns and adds valuable deep link tracking capabilities. Ready for merge! π |
Summary by CodeRabbit
New Features
Tests