Lead scoring implementation on website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Lead Scoring System Implementation on Website

Lead scoring is assigning a numerical score to each lead based on demographic data and behavior. Allows sales managers to focus on hot leads and automatically transfer them to CRM upon reaching a threshold.

Data Model

// Table schema
Schema::create('lead_scores', function (Blueprint $table) {
    $table->id();
    $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
    $table->string('session_id')->index();
    $table->string('email')->nullable()->index();
    $table->integer('score')->default(0);
    $table->json('score_breakdown');      // {"pricing_visit": 15, "demo_watched": 25}
    $table->string('stage')->default('cold');  // cold, warm, hot, mql, sql
    $table->timestamp('mql_reached_at')->nullable();
    $table->timestamp('qualified_at')->nullable();
    $table->timestamps();
    $table->index(['score', 'stage']);
});

Schema::create('lead_events', function (Blueprint $table) {
    $table->id();
    $table->foreignId('lead_score_id')->constrained()->cascadeOnDelete();
    $table->string('event');
    $table->integer('points');
    $table->json('metadata')->nullable();
    $table->timestamps();
});

Scoring Points Configuration

// config/lead_scoring.php
return [
    'events' => [
        // Behavioral signals
        'page_view_pricing'          => 15,
        'page_view_case_study'       => 10,
        'page_view_demo'             => 20,
        'demo_requested'             => 50,
        'whitepaper_downloaded'      => 20,
        'webinar_registered'         => 25,
        'free_trial_started'         => 40,
        'pricing_calculator_used'    => 30,
        'comparison_page_viewed'     => 15,
        'contact_form_submitted'     => 40,

        // Engagement
        'email_opened'               => 5,
        'email_clicked'              => 10,
        'return_visit'               => 5,
        'visited_3_days_in_row'      => 15,

        // Fit signals (via form)
        'company_size_50_plus'       => 20,
        'role_decision_maker'        => 25,
        'budget_confirmed'           => 30,

        // Negative signals
        'unsubscribed'               => -20,
        'inactive_30_days'           => -10,
        'student_email_domain'       => -25,
    ],

    'thresholds' => [
        'warm' => 30,
        'hot'  => 60,
        'mql'  => 80,   // Marketing Qualified Lead → send to CRM
        'sql'  => 100,  // Sales Qualified Lead → immediate manager call
    ],
];

Scoring Service

class LeadScoringService
{
    public function track(string $sessionId, string $event, array $metadata = [], ?int $userId = null): LeadScore
    {
        $points = config("lead_scoring.events.{$event}", 0);

        $lead = LeadScore::firstOrCreate(
            ['session_id' => $sessionId],
            ['user_id' => $userId, 'score_breakdown' => []]
        );

        if ($userId && !$lead->user_id) {
            $lead->update(['user_id' => $userId]);
        }

        // Email identification from metadata
        if (!empty($metadata['email']) && !$lead->email) {
            $lead->update(['email' => $metadata['email']]);
        }

        // Some events counted only once
        $onceEvents = ['demo_requested', 'free_trial_started', 'contact_form_submitted'];
        if (in_array($event, $onceEvents)) {
            if (LeadEvent::where('lead_score_id', $lead->id)->where('event', $event)->exists()) {
                return $lead;
            }
        }

        // Record event
        LeadEvent::create([
            'lead_score_id' => $lead->id,
            'event'         => $event,
            'points'        => $points,
            'metadata'      => $metadata,
        ]);

        // Update score and breakdown
        $breakdown = $lead->score_breakdown ?? [];
        $breakdown[$event] = ($breakdown[$event] ?? 0) + $points;

        $newScore = $lead->score + $points;
        $newStage = $this->calculateStage($newScore);

        $lead->update([
            'score'           => $newScore,
            'score_breakdown' => $breakdown,
            'stage'           => $newStage,
        ]);

        // Triggers on threshold reach
        $thresholds = config('lead_scoring.thresholds');
        $prevStage  = $this->calculateStage($lead->score - $points);

        if ($newStage !== $prevStage) {
            $this->onStageChange($lead, $prevStage, $newStage);
        }

        return $lead->fresh();
    }

    private function calculateStage(int $score): string
    {
        $thresholds = config('lead_scoring.thresholds');
        if ($score >= $thresholds['sql'])  return 'sql';
        if ($score >= $thresholds['mql'])  return 'mql';
        if ($score >= $thresholds['hot'])  return 'hot';
        if ($score >= $thresholds['warm']) return 'warm';
        return 'cold';
    }

    private function onStageChange(LeadScore $lead, string $from, string $to): void
    {
        Log::info("Lead stage change: {$from} → {$to}", ['lead_id' => $lead->id, 'score' => $lead->score]);

        if ($to === 'mql') {
            $lead->update(['mql_reached_at' => now()]);
            // Send to CRM
            SyncLeadToCrm::dispatch($lead);
            // Marketing notification
            Notification::route('slack', '#leads-hot')
                ->notify(new MqlReachedNotification($lead));
        }

        if ($to === 'sql') {
            $lead->update(['qualified_at' => now()]);
            // Immediate sales manager notification
            $salesManager = User::salesManager()->inRandomOrder()->first();
            $salesManager?->notify(new SqlLeadAssigned($lead));
        }
    }
}

Frontend: Event Tracking

// lib/lead-tracking.ts
class LeadTracker {
  private sessionId: string;

  constructor() {
    this.sessionId = sessionStorage.getItem('ls_session') || this.generateId();
    sessionStorage.setItem('ls_session', this.sessionId);
  }

  async track(event: string, metadata: Record<string, any> = {}): Promise<void> {
    try {
      await fetch('/api/lead-score/track', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          session_id: this.sessionId,
          event,
          metadata: { ...metadata, page: window.location.pathname },
        }),
      });
    } catch (e) {
      // Don't block UI on tracking error
    }
  }

  private generateId(): string {
    return Date.now().toString(36) + Math.random().toString(36).substr(2);
  }
}

export const tracker = new LeadTracker();

// Usage:
// View pricing page
tracker.track('page_view_pricing');

// Watch demo video (> 60 seconds)
videoElement.addEventListener('timeupdate', () => {
  if (videoElement.currentTime > 60 && !trackedDemo) {
    trackedDemo = true;
    tracker.track('demo_watched');
  }
});

// Download whitepaper
function downloadWhitepaper(email: string) {
  tracker.track('whitepaper_downloaded', { email });
}

Dashboard for Managers

-- Hot leads for last 7 days
SELECT
  ls.email,
  ls.score,
  ls.stage,
  ls.mql_reached_at,
  COUNT(le.id) AS events_count,
  MAX(le.created_at) AS last_activity
FROM lead_scores ls
JOIN lead_events le ON le.lead_score_id = ls.id
WHERE ls.stage IN ('mql', 'sql', 'hot')
  AND ls.mql_reached_at >= now() - interval '7 days'
GROUP BY ls.id, ls.email, ls.score, ls.stage, ls.mql_reached_at
ORDER BY ls.score DESC;

Timeline

Lead scoring system with configurable rules, CRM integration, and dashboard: 8-12 business days.