Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Jul 20, 2025

Summary by CodeRabbit

  • New Features

    • Added support for tracking new trigger types, including "Page View" and "Deep Link", in analytics.
    • Improved labeling for QR code scans in analytics displays.
  • Enhancements

    • Tracking events now include a trigger property for more detailed analytics.
    • Removed obsolete fields from click event data to streamline analytics processing.

@vercel
Copy link
Contributor

vercel bot commented Jul 20, 2025

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated (UTC)
dub βœ… Ready (Inspect) Visit Preview Jul 20, 2025 4:45am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 20, 2025

Walkthrough

The changes introduce a new trigger property to the click tracking system, updating the recordClick function and related constants to support additional trigger types such as "pageview" and "deeplink". The function signature and constants are updated accordingly. Additionally, the alias_link_id and user_id fields are removed from multiple data objects and Tinybird datasource schemas.

Changes

File(s) Change Summary
.../api/track/visit/route.ts Adds trigger: "pageview" to the argument passed to recordClick when hostnames are verified.
.../lib/analytics/constants.ts Updates TRIGGER_DISPLAY labels, adds "pageview" and "deeplink" keys, and extends TRIGGER_TYPES.
.../lib/tinybird/record-click.ts Updates recordClick function: adds optional trigger parameter (default "link"), uses in logic.
.../api/cron/framer/backfill-leads-batch/route.ts Removes alias_link_id property with empty string from click data objects; adds trigger: "link".
.../scripts/format-clicks.ts Removes alias_link_id property with empty string from click data objects.
.../scripts/framer/3-backfill-tb-events.ts Removes alias_link_id property with empty string from click data objects; adds trigger: "link".
.../scripts/seed-data.ts Removes alias_link_id property with empty string from click data objects; adds trigger: "link".
.../scripts/tinybird/update-click-event.ts Removes alias_link_id property with empty string from updated click data objects.
packages/tinybird/datasources/dub_click_events.datasource Removes alias_link_id and user_id fields from datasource schema.
packages/tinybird/datasources/dub_click_events_id.datasource Removes alias_link_id and user_id fields from datasource schema.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Route
    participant RecordClick
    Note over API_Route: Hostname verification
    Client->>API_Route: Track visit request
    API_Route->>RecordClick: recordClick(..., trigger: "pageview")
    RecordClick->>RecordClick: Determine trigger (QR or provided)
    RecordClick->>RecordClick: Record click data with trigger
Loading

Suggested reviewers

  • devkiran

Poem

A trigger here, a trigger there,
Now clicks are tracked with extra care!
Pageviews and links, deep in the code,
New labels and types on the analytics road.
So let the data flow and growβ€”
πŸ‡ Cheers to triggers, on we go!


πŸ“œ Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between d2bfa41 and c558e83.

πŸ“’ Files selected for processing (3)
  • apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts (1 hunks)
  • apps/web/scripts/framer/3-backfill-tb-events.ts (1 hunks)
  • apps/web/scripts/seed-data.ts (1 hunks)
βœ… Files skipped from review due to trivial changes (1)
  • apps/web/scripts/framer/3-backfill-tb-events.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/scripts/seed-data.ts
  • apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts
⏰ 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
✨ Finishing Touches
  • πŸ“ Generate Docstrings

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
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/web/lib/tinybird/record-click.ts (1)

55-55: Consider using a type union for better type safety.

While the current string type works, consider using a type union based on the TRIGGER_TYPES constant for better type safety and IntelliSense support.

+ import { TRIGGER_TYPES } from "@/lib/analytics/constants";
+ 
+ type TriggerType = typeof TRIGGER_TYPES[number];

- trigger?: string;
+ trigger?: TriggerType;
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 0887e56 and 5dcab1c.

πŸ“’ Files selected for processing (3)
  • apps/web/app/(ee)/api/track/visit/route.ts (1 hunks)
  • apps/web/lib/analytics/constants.ts (1 hunks)
  • apps/web/lib/tinybird/record-click.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
apps/web/lib/analytics/constants.ts (3)
Learnt from: devkiran
PR: dubinc/dub#2637
File: apps/web/app/(ee)/api/singular/webhook/route.ts:0-0
Timestamp: 2025-07-17T06:41:45.598Z
Learning: In the Singular integration (apps/web/app/(ee)/api/singular/webhook/route.ts), the event names in the singularToDubEvent object have intentionally different casing: "Copy GAID" and "copy IDFA". This casing difference is valid and should not be changed, as these are the correct event names expected from Singular.
Learnt from: TWilson023
PR: dubinc/dub#2519
File: apps/web/ui/analytics/utils.ts:35-37
Timestamp: 2025-06-16T19:21:23.506Z
Learning: In the `useAnalyticsFilterOption` function in `apps/web/ui/analytics/utils.ts`, the pattern `options?.context ?? useContext(AnalyticsContext)` is intentionally designed as a complete replacement strategy, not a merge. When `options.context` is provided, it should contain all required fields (`baseApiPath`, `queryString`, `selectedTab`, `requiresUpgrade`) and completely replace the React context, not be merged with it. This is used for dependency injection or testing scenarios.
Learnt from: devkiran
PR: dubinc/dub#2448
File: packages/email/src/templates/partner-program-summary.tsx:0-0
Timestamp: 2025-05-29T04:45:18.504Z
Learning: In the PartnerProgramSummary email template (packages/email/src/templates/partner-program-summary.tsx), the stat titles are hardcoded constants ("Clicks", "Leads", "Sales", "Earnings") that will always match the ICONS object keys after toLowerCase() conversion, so icon lookup failures are not possible.
⏰ 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 (5)
apps/web/lib/analytics/constants.ts (1)

210-216: LGTM! Well-structured trigger enum additions.

The updates correctly add the new trigger types pageview and deeplink to both the display mapping and the types array. The QR label change from "QR Scan" to "QR Code Scan" improves clarity and consistency.

apps/web/app/(ee)/api/track/visit/route.ts (1)

101-101: LGTM! Correct usage of the new pageview trigger.

The addition of trigger: "pageview" appropriately categorizes this click recording as a page view event, which aligns with the new trigger types defined in the constants file.

apps/web/lib/tinybird/record-click.ts (3)

41-41: LGTM! Well-implemented trigger parameter.

The default value of "link" is appropriate for the majority of click events, and the optional parameter design maintains backward compatibility.

Also applies to: 55-55


99-101: LGTM! Correct QR detection override logic.

The conditional override to set trigger = "qr" when QR is detected maintains the existing QR tracking behavior while allowing other trigger types to be explicitly specified.


157-157: LGTM! Trigger properly included in click data.

The trigger value is correctly added to the clickData object for analytics tracking.

@steven-tey
Copy link
Collaborator Author

@CodeRabbit final review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 20, 2025

Tip

For best results, initiate chat on the files or code changes.

@steven-tey Looking at this PR comprehensively, this is a well-executed feature addition! Here's my final review:

βœ… Strengths

Systematic Implementation:

  • The trigger enum system is consistently implemented across all relevant files
  • Default value of "link" maintains backward compatibility
  • Proper handling of QR code detection to override trigger type

Clean Data Schema:

  • Removal of unused alias_link_id and user_id fields from Tinybird datasources
  • Consistent cleanup across all data generation scripts and API endpoints

Type Safety:

  • Good use of TypeScript with proper enum definitions in TRIGGER_TYPES
  • Clear mapping in TRIGGER_DISPLAY for UI representation

🎯 Implementation Quality

The changes follow a clear pattern:

  1. Core Logic: Updated recordClick function with optional trigger parameter
  2. Constants: Extended trigger types and display mappings
  3. Usage: Applied new trigger values in appropriate contexts ("pageview" for visit tracking, "link" as default)
  4. Schema: Cleaned up unused fields from data sources

πŸš€ Ready for Merge

The PR successfully:

  • βœ… Adds comprehensive trigger tracking capability
  • βœ… Maintains backward compatibility
  • βœ… Cleans up technical debt (unused fields)
  • βœ… Provides clear labeling for different trigger types
  • βœ… Updates all relevant data generation and backfill scripts

No issues found - this is ready for merge! πŸŽ‰

    (\   /)
   ( ._. )
  o_(")(")  Great work on the systematic implementation!

@steven-tey steven-tey merged commit e8cfce1 into main Jul 20, 2025
8 checks passed
@steven-tey steven-tey deleted the trigger branch July 20, 2025 04:54
@coderabbitai coderabbitai bot mentioned this pull request Aug 4, 2025
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.

2 participants