Skip to main content

Overview

The certificate system in Dashboard Dilemas allows you to generate and distribute digital certificates for users who complete games. Two types of certificates are available:
  • Participation Certificate: Awarded for completing a game
  • Excellence Certificate: Awarded for achieving outstanding scores

generate_certificate

Generates a certificate PDF for a user’s game completion.
This is actually a PHP page rather than a function. The page is accessed via URL with query parameters and generates a viewable/downloadable certificate.

Access URL

generate_certificate.php?user_id={userId}&game_id={gameId}&type={type}

Parameters

user_id
string
required
User ID who completed the game. Can be numeric ID or email for guest users.
game_id
integer
required
Game (dilemma) ID for which the certificate is being generated.
type
string
default:"'participation'"
Certificate type: ‘participation’ or ‘award’

Certificate Types

Awarded when a user completes any game session.Visual Style:
  • Blue accent color scheme
  • Standard certificate border
  • Completion acknowledgment text
Title: “Certificado de Participación”Subtitle: “Por haber completado exitosamente la actividad del dilema”

Certificate Contents

Each certificate includes:
header
section
  • Dilemas Éticos logo
  • Client logo (if available)
body
section
  • Certificate type title
  • Recipient name
  • Game/dilemma name
  • Score badge (for excellence certificates)
  • Session date
  • Signature line (“Comité Evaluador”)
  • Audit code (format: DE--)
  • QR code placeholder

Example Usage

// Generate participation certificate
$url = "generate_certificate.php?user_id=42&game_id=10&type=participation";

// Generate excellence certificate
$url = "generate_certificate.php?user_id=42&game_id=10&type=award";

Page Actions

The certificate page provides two main actions:
1

Send by Email

Triggers the email sending function via AJAX call to api_send_certificate.php
function sendEmail() {
    const formData = new FormData();
    formData.append('user_id', userId);
    formData.append('game_id', gameId);
    formData.append('type', certificateType);
    
    fetch('api_send_certificate.php', {
        method: 'POST',
        body: formData
    });
}
2

Download PDF

Generates a PDF using html2pdf library with optimized settings
function downloadPDF(event) {
    const opt = {
        margin: 0,
        filename: 'Certificado_User_Name.pdf',
        image: { type: 'jpeg', quality: 1 },
        html2canvas: {
            scale: 4,
            useCORS: true,
            letterRendering: true,
            windowWidth: 1120
        },
        jsPDF: {
            unit: 'mm',
            format: 'a4',
            orientation: 'landscape',
            compress: true
        }
    };
    
    html2pdf().set(opt).from(element).save();
}

Certificate Email Distribution

api_send_certificate.php

Sends a certificate to a user via email using WordPress’s wp_mail() function.

Endpoint

POST api_send_certificate.php

Parameters

user_id
string
required
User ID or email address
game_id
integer
required
Game ID
type
string
default:"'participation'"
Certificate type: ‘participation’ or ‘award’

Response

success
boolean
Whether the email was sent successfully
message
string
Error message (only present when success is false)

Example Request

const formData = new FormData();
formData.append('user_id', '42');
formData.append('game_id', '10');
formData.append('type', 'award');

fetch('api_send_certificate.php', {
    method: 'POST',
    body: formData
})
.then(res => res.json())
.then(data => {
    if (data.success) {
        console.log('Certificate sent!');
    } else {
        console.error('Error:', data.message);
    }
});

Email Template

The email includes:

Email structure

Subject Line:
  • Participation: ”📜 Tu Certificado de Participación - {Game Name}”
  • Excellence: ”🏆 ¡Felicidades! Tu Certificado de Excelencia - {Game Name}”
Body:
  • Professional HTML template with gradient header
  • Personalized greeting
  • Congratulatory message
  • Download button linking to certificate page
  • Footer with disclaimer
Design:
  • Responsive design (max-width: 600px)
  • Blue gradient header for brand identity
  • Rounded corners and shadows
  • Mobile-friendly button styling

Funnel Event Tracking

Both certificate generation and email sending register events in the funnel analytics:
  • cert_sent: Registered when email is sent
  • cert_downloaded: Registered when PDF is generated
// Email sent event
$stmtFunnel = $pdo->prepare(
    "INSERT INTO de_app_funnel_events (game_id, user_id, event_type) 
     VALUES (:gameId, :userId, 'cert_sent')"
);
$stmtFunnel->execute(['gameId' => $gameId, 'userId' => $userId]);

// Certificate downloaded event
$stmtFunnel = $pdo->prepare(
    "INSERT INTO de_app_funnel_events (game_id, user_id, event_type) 
     VALUES (:gameId, :userId, 'cert_downloaded')"
);
$stmtFunnel->execute(['gameId' => $gameId, 'userId' => $userId]);

Implementation Example

Complete workflow for awarding certificates:
// 1. User completes a game session
$session = get_session_details($sessionId);

// 2. Determine certificate type based on score
$certificateType = ($session['score'] >= 80) ? 'award' : 'participation';

// 3. Generate certificate URL
$certificateUrl = SITE_URL . "/generate_certificate.php?" . http_build_query([
    'user_id' => $session['id'],
    'game_id' => $gameId,
    'type' => $certificateType
]);

// 4. Send certificate email
$emailData = [
    'user_id' => $session['id'],
    'game_id' => $gameId,
    'type' => $certificateType
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, SITE_URL . '/api_send_certificate.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $emailData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$result = json_decode($response, true);

if ($result['success']) {
    echo "Certificate sent to " . $session['email'];
} else {
    error_log("Failed to send certificate: " . $result['message']);
}

curl_close($ch);

Best Practices

Score Thresholds

Set clear criteria for excellence certificates. The default threshold is typically 80% or higher.

Email Validation

Always validate user email addresses exist before attempting to send certificates.

Error Handling

Implement proper error logging and user feedback for failed certificate generation or email delivery.

Rate Limiting

Consider implementing rate limiting to prevent abuse of certificate generation endpoints.

Sessions

Retrieve session data needed for certificates

Users

Get user information for certificates

Build docs developers (and LLMs) love