Skip to content

๐Ÿ’Ž A flexible Ruby gem to add loyalty points, dynamic tiers, and referral rewards to any Rails app. Track signups, clicks, and geolocation with zero setup.

License

Notifications You must be signed in to change notification settings

KapilDevPal/LoyaltyRef

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ReferralBox ๐Ÿ“ฆ

PLEASE VISIT THIS GEM BEEN Updated https://github.com/KapilDevPal/Referral_box

A flexible Ruby gem for building loyalty and referral systems in Rails apps.

  • ๐ŸŽ Reward users with points based on their activity
  • ๐Ÿงฑ Create dynamic tier levels (Silver, Gold, Platinum)
  • ๐Ÿค Add referral rewards with unique referral codes
  • ๐Ÿ”ง Fully customizable and configurable
  • ๐ŸŽ›๏ธ Admin dashboard (ERB based)
  • ๐Ÿ”„ Supports any user model: User, Customer, Account, etc.

๐Ÿ“š Documentation


๐Ÿš€ Installation

# Gemfile
gem 'referral_box'
$ bundle install
$ rails generate referral_box:install
$ rails db:migrate

๐Ÿ› ๏ธ Configuration

Create your configuration block in an initializer:

# config/initializers/referral_box.rb

ReferralBox.configure do |config|
  # Define which model represents your app's user/customer
  config.reference_class_name = 'User' # or 'Customer', 'Account', etc.

  config.earning_rule = ->(user, event) do
    # Example: earn 10 points per โ‚น100 spent
    event.amount / 10
  end

  config.redeem_rule = ->(user, offer) do
    offer.cost_in_points
  end

  config.tier_thresholds = {
    "Silver" => 500,
    "Gold" => 1000,
    "Platinum" => 2500
  }

  config.reward_modifier = ->(user) do
    case user.tier
    when "Silver" then 1.0
    when "Gold" then 1.2
    when "Platinum" then 1.5
    else 1.0
    end
  end

  config.referral_reward = ->(referrer, referee) do
    ReferralBox.earn_points(referrer, 100)
    ReferralBox.earn_points(referee, 50)
  end
end

โœ… Features

๐ŸŽ Loyalty Program

Feature Description
Points system Earn points via config lambda
Custom earning rules Define rules per event/user
Redeem points Redeem points for offers
Manual adjustment Admins can modify balances
Points expiration e.g. 90 days
Transaction logging All activity is logged
Check balance Easy method to check

๐Ÿงฑ Tier System (Dynamic)

Feature Description
Dynamic definitions e.g. Silver => 500 points
Auto tier assignment Based on balance
Callbacks on promotion on_tier_changed hook
Reward modifier by tier e.g. Gold users get +20%
DB persistence Can store or calculate tier

๐Ÿค Referral System

Feature Description
Unique referral codes Auto-generated or custom
?ref=code tracking Via signup links
Multi-level referrals Parent/child tree
Referral rewards Custom logic supported
Referral analytics Track clicks, accepted signups, geo-location, and device type

โš™๏ธ Core Gem Features

  • Developer config block
  • Extensible models
  • Simple public API: earn_points, redeem_points, balance, track_referral
  • Rails generators for setup
  • Support for any user model (User, Account, Customer, etc.)

๐Ÿ–ฅ๏ธ Admin UI

  • Mountable engine with ERB templates
  • Routes like /referral_box
  • Views to list users, transactions, referrals

๐Ÿ”ฎ Future Scope

๐Ÿ“Š Analytics & Admin

  • Leaderboards by points
  • Referral tree visualizer
  • ActiveAdmin / custom dashboard
  • Export CSV/JSON of logs

๐Ÿ”” Engagement

  • Email / in-app notifications
  • Badges based on milestones
  • Activity calendar
  • Social sharing for referral links

๐Ÿ“‚ Folder Structure (Gem)

lib/
โ”œโ”€โ”€ referral_box.rb
โ”œโ”€โ”€ referral_box/
โ”‚   โ”œโ”€โ”€ engine.rb
โ”‚   โ”œโ”€โ”€ configuration.rb
โ”‚   โ”œโ”€โ”€ version.rb
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ transaction.rb
โ”‚   โ”‚   โ”œโ”€โ”€ referral_log.rb
โ”‚   โ””โ”€โ”€ controllers/
โ”‚       โ”œโ”€โ”€ dashboard_controller.rb
app/views/referral_box/dashboard/
  โ”œโ”€โ”€ index.html.erb
  โ”œโ”€โ”€ show.html.erb

๐Ÿงช Usage Examples

# Earn points
ReferralBox.earn_points(current_user, event: order)

# Redeem points
ReferralBox.redeem_points(current_user, offer: coupon)

# Check balance
ReferralBox.balance(current_user)

# Track referral
ReferralBox.track_referral(ref_code: params[:ref])

๐Ÿ“ฌ Contribution

PRs are welcome ๐Ÿ™Œ โ€” help improve the gem or suggest features.

๐Ÿ“œ License

MIT ยฉ 2025 Kapil Pal

About

๐Ÿ’Ž A flexible Ruby gem to add loyalty points, dynamic tiers, and referral rewards to any Rails app. Track signups, clicks, and geolocation with zero setup.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published