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

new referral scheme #1255

Merged
merged 5 commits into from
Jul 7, 2024
Merged

new referral scheme #1255

merged 5 commits into from
Jul 7, 2024

Conversation

huumn
Copy link
Member

@huumn huumn commented Jul 6, 2024

So far this captures the relevant referral data in middleware.js, storing it in cookies (for a future login), and passing it in the request headers (for logged in stackers) for storage in the db.

how this is going to work

  • referrals can be earned the following ways:
    • explicit referrals by sharing links with /r/<referrer name> at the end or invite links
    • implicit referrals:
      • every item link attributes a referral to the OP
      • every item link with a commentId attributes a referral to the comment's OP
      • every profile page link attributes a referral to the stacker on the profile
      • every territory link attributes a referral to the territory founder
  • for logged out stackers, we store referrals in their cookies to be used on signup:
    • sn_referrer is set by either explicit or implicit referrals for 24 hours
    • if a stacker is referred again by an explicit referral within that 24 hour period, it is overwritten
    • if a stacker is referred again by an implicit referral within that 24 hour period, it is NOT overwritten
  • for logged in stackers, in addition to the signup referrals, we catalog every explicit and implicit referral they receive in the OneDayReferral table
    • at the end of the day, for each referee, the most frequent referrer of the referee (ie contributed the most rows to the OneDayReferral table for the referee) is crowned the "one day referrer" of the referee
    • the "one day referrer" of the referee gets 50% of the referee's referral rewards, and the referee's original referrer (ie users.referrerId) get the other 50%
  • 20% of all daily rewards will be distributed to the referrers of the daily reward earners (ie the people on the rewards leaderboard)

todos

  • attribute either implicit or explicit referrer on signup
  • use the OneDayReferrral table and users.referrerId to dole out daily referral rewards

if (!parent.total) {
return 0
}
return parent.total
Copy link
Member Author

Choose a reason for hiding this comment

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

This was throwing errors in development.

const referrerPattern = new URLPattern({ pathname: ':pathname(*)/r/:referrer([\\w_]+)' })
const itemPattern = new URLPattern({ pathname: '/items/:id(\\d+)' })
const profilePattern = new URLPattern({ pathname: '/:name([\\w_]+){/:type(\\w+)}?' })
const territoryPattern = new URLPattern({ pathname: '/~:name([\\w_]+){/*}?' })
Copy link
Member Author

@huumn huumn Jul 6, 2024

Choose a reason for hiding this comment

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

These are waayyyyyyyyyy better than using regex for urls.

Copy link
Member

Choose a reason for hiding this comment

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

Mhh, interesting!

I wish we could use this in the browser, too, but it's not supported by every major browser yet according to MDN:

2024-07-07-043155_780x338_scrot

It's also not implemented in node yet, see nodejs/node#40844.

So cool that next/server has this implemented!

@huumn huumn marked this pull request as ready for review July 6, 2024 23:11
@huumn huumn requested a review from ekzyis July 6, 2024 23:11
@huumn
Copy link
Member Author

huumn commented Jul 6, 2024

@ekzyis I marked this ready for review because I want to deploy this before implementing referral rewards so that I can have a real data set to test rewards on.

Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

Looks good to me! Tested interaction between referrerMiddleware and oneDayReferral and did not find any issue.

const referrerPattern = new URLPattern({ pathname: ':pathname(*)/r/:referrer([\\w_]+)' })
const itemPattern = new URLPattern({ pathname: '/items/:id(\\d+)' })
const profilePattern = new URLPattern({ pathname: '/:name([\\w_]+){/:type(\\w+)}?' })
const territoryPattern = new URLPattern({ pathname: '/~:name([\\w_]+){/*}?' })
Copy link
Member

Choose a reason for hiding this comment

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

Mhh, interesting!

I wish we could use this in the browser, too, but it's not supported by every major browser yet according to MDN:

2024-07-07-043155_780x338_scrot

It's also not implemented in node yet, see nodejs/node#40844.

So cool that next/server has this implemented!

middleware.js Outdated Show resolved Hide resolved
@huumn
Copy link
Member Author

huumn commented Jul 7, 2024

Great review! I incorporated all your feedback.

@huumn huumn merged commit 3bada4b into master Jul 7, 2024
6 checks passed
@huumn huumn deleted the refs branch July 7, 2024 16:12
@huumn huumn restored the refs branch July 11, 2024 00:14
@huumn huumn deleted the refs branch July 11, 2024 00:19
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