Skip to content
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

Referral Link Generation & Association #97

Open
5 tasks done
limwa opened this issue Feb 10, 2025 · 1 comment · May be fixed by #33
Open
5 tasks done

Referral Link Generation & Association #97

limwa opened this issue Feb 10, 2025 · 1 comment · May be fixed by #33
Milestone

Comments

@limwa
Copy link
Member

limwa commented Feb 10, 2025

User Story:
As a participant or promoter, I want to generate a unique referral link so that I can invite others to register for the event.

Acceptance Criteria:

  • Every participant and promoter receives a unique referral link.
  • Referral links only become available after the user has purchased a ticket.
  • When someone clicks a referral link:
    • The browser associates the visitor with the referring user via cookies/session storage.
    • If the visitor creates an account, they are linked to the referrer.
    • If the visitor is already logged in, the system updates their referral association.
  • Considerations for social media links:
    • Links opened on Instagram should correctly associate the referral, despite opening in a new browser.
    • Prevent browsers from prefetching referral links and falsely triggering tracking.
  • Referral tracking data is stored securely and cannot be changed manually by users.
@limwa limwa added this to the Road Show milestone Feb 10, 2025
@limwa
Copy link
Member Author

limwa commented Feb 11, 2025

Proposed Implementation

Every participant and promoter receives a unique referral link.

  1. Create a new route for referrals.
router.route(`/r/:slug`, ['GET', 'POST'], [ReferralController, 'link'])
  .middleware(middleware.automaticSubmit())
  .as('actions:referrals.link')
  1. Each user gets a public profile slug (referenced in Public Profile Accessibility via Credential Scan #69). As such, each user then has a referral link https://eneiconf.pt/r/<slug>. The URL doesn't need to be signed. The signed URL is generated using app/url.ts:
const referralUrl = buildUrl()
  .params({ slug: user.slug })
  .make('actions:referrals.link')
  1. The referral URL page is only accessible to participants and promoters.

Referral links only become available after the user has purchased a ticket.

To enforce this, the ReferralController must check that the user referenced in the slug already has a ticket. The browser/user is only linked to the promoter if that check is successful.

When someone clicks a referral link: ...

  1. If the user is not logged in, the controller creates a cookie valid for 7 days and named referrer on the browser with the id of the referrer. This is made to endure changes in the slug (if the user changes the name, for instance).
  2. Create a middleware, using node ace make:middleware LinkToUserMiddleware.
  3. On the middleware, check if the referrer cookie exists. If it does, use await auth.check() to silently authenticate the user. Then, use if (auth.user) to get the user. Link the user to the referrer that is stored in the cookie.

@limwa limwa linked a pull request Feb 18, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant