feat: integrate @vercel/analytics for enhanced tracking and analytics#57
Open
ej020586 wants to merge 1 commit into
Open
feat: integrate @vercel/analytics for enhanced tracking and analytics#57ej020586 wants to merge 1 commit into
ej020586 wants to merge 1 commit into
Conversation
… capabilities; refactor layout and components for improved structure and UX
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
🗺️ Roadmap Sync PreviewThis is a dry-run preview. Changes will be applied when merged to main. |
Contributor
Greptile OverviewGreptile SummaryIntegrates Vercel Analytics with a custom extensible tracking abstraction layer and anyclick-protocol intent system for comprehensive homepage analytics. Key Changes:
Architecture:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant HomePage as HomePageClient
participant IntentProvider
participant TrackingManager
participant VercelProvider
participant Analytics as @vercel/analytics
User->>HomePage: Page loads
HomePage->>IntentProvider: Mount
IntentProvider->>TrackingManager: configure() + registerProvider()
IntentProvider->>TrackingManager: Register vercelProvider
IntentProvider->>TrackingManager: Register consoleProvider (dev only)
IntentProvider->>IntentProvider: useScrollDepth()
IntentProvider->>IntentProvider: useTimeOnPage()
User->>HomePage: Clicks nav link
HomePage->>TrackingManager: track(NAV_DOCS_CLICK)
TrackingManager->>VercelProvider: track(event)
VercelProvider->>Analytics: track("web.homepage.nav.docs.click", properties)
User->>HomePage: Scrolls page
Note over HomePage: IntersectionObserver detects hero section
HomePage->>TrackingManager: track(HERO_VIEW)
TrackingManager->>VercelProvider: track(event)
VercelProvider->>Analytics: track("web.homepage.hero.view", engagement)
Note over HomePage: Scroll reaches 50%
HomePage->>TrackingManager: track(SCROLL_DEPTH_50)
TrackingManager->>VercelProvider: track(event)
VercelProvider->>Analytics: track("web.homepage.scroll.depth.50", scrollDepth)
User->>HomePage: Hovers feature card
HomePage->>TrackingManager: track(FEATURES_CARD_HOVER)
TrackingManager->>VercelProvider: track(event)
VercelProvider->>Analytics: track("web.homepage.features.card.hover", properties)
User->>HomePage: Page unload
HomePage->>TrackingManager: flush()
TrackingManager->>VercelProvider: flush()
|
Comment on lines
+54
to
+66
| const trackHover = useCallback( | ||
| (intent: string, properties?: Record<string, unknown>) => { | ||
| let tracked = false; | ||
| return () => { | ||
| // Only track once per mount | ||
| if (!tracked) { | ||
| tracked = true; | ||
| getTrackingManager().track(intent, { properties }); | ||
| } | ||
| }; | ||
| }, | ||
| [] | ||
| ); |
Contributor
There was a problem hiding this comment.
logic: trackHover creates a new closure on every call, each with its own tracked variable. If the same hover handler is created multiple times (e.g., on re-renders), each instance tracks independently, potentially causing duplicate events.
Suggested change
| const trackHover = useCallback( | |
| (intent: string, properties?: Record<string, unknown>) => { | |
| let tracked = false; | |
| return () => { | |
| // Only track once per mount | |
| if (!tracked) { | |
| tracked = true; | |
| getTrackingManager().track(intent, { properties }); | |
| } | |
| }; | |
| }, | |
| [] | |
| ); | |
| const trackHover = useCallback( | |
| (intent: string, properties?: Record<string, unknown>) => { | |
| const trackedRef = { current: false }; | |
| return () => { | |
| // Only track once per handler instance | |
| if (!trackedRef.current) { | |
| trackedRef.current = true; | |
| getTrackingManager().track(intent, { properties }); | |
| } | |
| }; | |
| }, | |
| [] | |
| ); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/src/lib/tracking/hooks/useTrackIntent.ts
Line: 54:66
Comment:
**logic:** `trackHover` creates a new closure on every call, each with its own `tracked` variable. If the same hover handler is created multiple times (e.g., on re-renders), each instance tracks independently, potentially causing duplicate events.
```suggestion
const trackHover = useCallback(
(intent: string, properties?: Record<string, unknown>) => {
const trackedRef = { current: false };
return () => {
// Only track once per handler instance
if (!trackedRef.current) {
trackedRef.current = true;
getTrackingManager().track(intent, { properties });
}
};
},
[]
);
```
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vercel analytics with abstract layer and intent from anyclick-protocol