PHP code example of keyagency / kai-personalize

1. Go to this page and download the library: Download keyagency/kai-personalize library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

keyagency / kai-personalize example snippets


'features' => [
    'fingerprinting' => true,
    'ip_tracking' => true,
    'geolocation' => true,
    'behavioral_tracking' => true,
    'external_data' => true,
],

'privacy' => [
    'encrypt_ip' => true,
    'anonymize_after_days' => 30,
    'respect_dnt' => true,
    'gdpr_mode' => false,
],

// MaxMind GeoIP2 Local Database (no API calls needed)
'maxmind' => [
    'enabled' => true,
    'database_city' => 'app/geoip/GeoLite2-City.mmdb',
    'database_country' => 'app/geoip/GeoLite2-Country.mmdb',
    'database_asn' => 'app/geoip/GeoLite2-ASN.mmdb',
    'cache_duration' => 86400,
],

$this->call(BlacklistSeeder::class);

'features' => [
    'scroll_tracking' => true,   // Scroll depth, reading time, exit intent
    'click_tracking' => true,   // Clicks, rage clicks, dead clicks, hesitation
    'form_tracking' => false,   // Form interactions
    'video_tracking' => false,  // Video engagement
    'fingerprinting' => true,   // Browser fingerprinting
],

'enabled' => env('KAI_PERSONALIZE_ENABLED', true),

// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->validateCsrfTokens(except: [
        'kai-personalize/track',      // Main tracking endpoint
        'kai-personalize/*',          // All Kai Personalize routes
    ]);
})
bash
php artisan vendor:publish --tag=kai-personalize-config
php artisan vendor:publish --tag=kai-personalize-translations
bash
php artisan migrate
bash
# Test API connection
php artisan kai:test-activecampaign

# Test email lookup
php artisan kai:test-activecampaign [email protected]

# Test cookie-based retrieval (interactive)
php artisan kai:test-activecampaign --test-cookie
bash
php artisan db:seed --class=KeyAgency\\\\KaiPersonalize\\\\Database\\\\Seeders\\\\BlacklistSeeder
antlers
{{ kai:behavior }}
    {{ max_scroll_depth }}
    {{ total_reading_time_ms }}
    {{ total_clicks }}
    {{ total_events }}
{{ /kai:behavior }}
antlers
{{ kai:visitor }}
    {{ if is_returning }}
        <h1>Welcome back!</h1>
        <p>This is visit #{{ visit_count }}</p>
    {{ else }}
        <h1>Welcome!</h1>
        <p>First time here?</p>
    {{ /if }}
{{ /kai:visitor }}