### Read Mixpanel settings Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Retrieve the MixpanelSettings instance and access properties like project_token, debug, and record_sessions_percent. The example shows default values. ```php use JeffersonGoncalves\Mixpanel\Settings\MixpanelSettings; $settings = app(MixpanelSettings::class); echo $settings->project_token; // e.g., "abc123def456" echo $settings->debug; // false echo $settings->record_sessions_percent; // 0 ``` -------------------------------- ### Install laravel-mixpanel via Composer Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/README.md Install the package via Composer. Requires PHP 8.2+, Laravel 11+, and spatie/laravel-settings configured. ```bash composer require jeffersongoncalves/laravel-mixpanel ``` -------------------------------- ### Publish and run Mixpanel settings migration Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/README.md Publish and run the Mixpanel settings migration. Run after publishing the spatie/laravel-settings migration. ```bash php artisan vendor:publish --tag=mixpanel-settings-migrations php artisan migrate ``` -------------------------------- ### Publish spatie/laravel-settings migration Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/README.md Publish the spatie/laravel-settings migration to create the settings table if not already done. ```bash php artisan vendor:publish --provider="Spatie\LaravelSettings\LaravelSettingsServiceProvider" --tag="migrations" ``` -------------------------------- ### Create settings migration for new setting Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Migration to add the new setting to the database. ```php return new class extends SettingsMigration { public function up(): void { $this->migrator->add('mixpanel.record_idle_timeout_ms', false); } }; ``` -------------------------------- ### toJsConfig() method for Mixpanel settings Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Converts Mixpanel settings into an array suitable for mixpanel.init(). Handles type conversions: 'true'/'false' strings become booleans, comma-separated property_blacklist becomes an array, and api_host is only included when set. ```php public function toJsConfig(): array { $config = []; if ($this->api_host) { $config['api_host'] = $this->api_host; } $config['debug'] = $this->debug; $config['autocapture'] = $this->autocapture; // 'true'/'false' strings become booleans; other values pass through as strings if (in_array($this->track_pageview, ['true', 'false'], true)) { $config['track_pageview'] = $this->track_pageview === 'true'; } else { $config['track_pageview'] = $this->track_pageview; } $config['persistence'] = $this->persistence; $config['cookie_expiration'] = $this->cookie_expiration; $config['secure_cookie'] = $this->secure_cookie; $config['cross_subdomain_cookie'] = $this->cross_subdomain_cookie; $config['ip'] = $this->ip; // Comma-separated string becomes array if ($this->property_blacklist) { $config['property_blacklist'] = array_map('trim', explode(',', $this->property_blacklist)); } $config['opt_out_tracking_by_default'] = $this->opt_out_tracking_by_default; $config['stop_utm_persistence'] = $this->stop_utm_persistence; $config['record_sessions_percent'] = $this->record_sessions_percent; $config['record_heatmap_data'] = $this->record_heatmap_data; return $config; } ``` -------------------------------- ### Configure data residency for EU and India Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/README.md Set the api_host for EU or India data residency. The EU endpoint is https://api-eu.mixpanel.com and the India endpoint is https://api-in.mixpanel.com. ```php // EU Data Residency $settings->api_host = 'https://api-eu.mixpanel.com'; $settings->save(); // India Data Residency $settings->api_host = 'https://api-in.mixpanel.com'; $settings->save(); ``` -------------------------------- ### Set Mixpanel project token Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/README.md Configure the Mixpanel project token via the settings class. Settings are stored in the database. ```php use JeffersonGoncalves\Mixpanel\Settings\MixpanelSettings; $settings = app(MixpanelSettings::class); $settings->project_token = 'YOUR_MIXPANEL_PROJECT_TOKEN'; $settings->save(); ``` -------------------------------- ### MixpanelServiceProvider Class Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Service provider that registers the package, auto-registers MixpanelSettings, and publishes settings migrations. ```php class MixpanelServiceProvider extends PackageServiceProvider { public function configurePackage(Package $package): void { $package->name('laravel-mixpanel') ->hasViews(); } public function packageRegistered(): void { parent::packageRegistered(); Config::set('settings.settings', array_merge( Config::get('settings.settings', []), [MixpanelSettings::class] )); } public function packageBooted(): void { parent::packageBooted(); Config::set('settings.migrations_paths', array_merge( Config::get('settings.migrations_paths', []), [__DIR__.'/../database/settings'] )); $this->publishes([ __DIR__.'/../database/settings' => database_path('settings'), ], 'mixpanel-settings-migrations'); } } ``` -------------------------------- ### MixpanelSettings Class Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Settings class with all Mixpanel configuration properties and the group method. ```php use Spatie\LaravelSettings\Settings; class MixpanelSettings extends Settings { public ?string $project_token; public ?string $api_host; public ?string $custom_lib_url; public bool $debug; public bool $autocapture; public string $track_pageview; public string $persistence; public int $cookie_expiration; public bool $secure_cookie; public bool $cross_subdomain_cookie; public bool $ip; public ?string $property_blacklist; public bool $opt_out_tracking_by_default; public bool $stop_utm_persistence; public int $record_sessions_percent; public bool $record_heatmap_data; public static function group(): string { return 'mixpanel'; } public function toJsConfig(): array { /* ... */ } } ``` -------------------------------- ### Run Package Test Commands Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Use these Composer scripts to execute tests, check coverage, perform static analysis, and format code. ```bash # Run tests composer test # Run tests with coverage composer test-coverage # Run static analysis composer analyse # Run code formatting composer format ``` -------------------------------- ### Settings migration creating 16 settings Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Migration that adds all 16 settings to the 'mixpanel' group using spatie/laravel-settings. ```php return new class extends SettingsMigration { public function up(): void { $this->migrator->add('mixpanel.project_token', null); $this->migrator->add('mixpanel.api_host', null); $this->migrator->add('mixpanel.custom_lib_url', null); $this->migrator->add('mixpanel.debug', false); $this->migrator->add('mixpanel.autocapture', true); $this->migrator->add('mixpanel.track_pageview', 'true'); $this->migrator->add('mixpanel.persistence', 'cookie'); $this->migrator->add('mixpanel.cookie_expiration', 365); $this->migrator->add('mixpanel.secure_cookie', false); $this->migrator->add('mixpanel.cross_subdomain_cookie', true); $this->migrator->add('mixpanel.ip', true); $this->migrator->add('mixpanel.property_blacklist', null); $this->migrator->add('mixpanel.opt_out_tracking_by_default', false); $this->migrator->add('mixpanel.stop_utm_persistence', false); $this->migrator->add('mixpanel.record_sessions_percent', 0); $this->migrator->add('mixpanel.record_heatmap_data', false); } }; ``` -------------------------------- ### Package Directory Structure Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Directory structure of the laravel-mixpanel package. ```text src/ MixpanelServiceProvider.php # Package service provider Settings/ MixpanelSettings.php # Spatie Settings class (group: mixpanel) database/ settings/ 2026_01_01_000000_create_mixpanel_settings.php # Settings migration resources/ views/ script.blade.php # Tracking script Blade view ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/README.md Runs the test suite for the package using Composer's test script. ```bash composer test ``` -------------------------------- ### Configure proxy for Mixpanel requests Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/README.md Route Mixpanel requests through your own proxy by setting api_host and custom_lib_url. ```php $settings->api_host = 'https://proxy.yourdomain.com'; $settings->custom_lib_url = 'https://proxy.yourdomain.com/lib.min.js'; $settings->save(); ``` -------------------------------- ### Update Mixpanel settings Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Modify settings such as project_token, api_host, debug, and record_sessions_percent, then persist with save(). ```php $settings = app(MixpanelSettings::class); $settings->project_token = 'your-mixpanel-project-token'; $settings->api_host = 'https://api-eu.mixpanel.com'; $settings->debug = true; $settings->record_sessions_percent = 25; $settings->save(); ``` -------------------------------- ### Test MixpanelSettings Independent Defaults Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Verifies the default values assigned to the MixpanelSettings model and confirms its group association. ```php it('has the correct default values', function () { $settings = app(MixpanelSettings::class); expect($settings->project_token)->toBeNull(); expect($settings->debug)->toBeFalse(); expect($settings->autocapture)->toBeTrue(); expect($settings->track_pageview)->toBe('true'); expect($settings->persistence)->toBe('cookie'); expect($settings->cookie_expiration)->toBe(365); expect($settings->record_sessions_percent)->toBe(0); }); it('belongs to the mixpanel group', function () { expect(MixpanelSettings::group())->toBe('mixpanel'); }); ``` -------------------------------- ### Set custom API host for EU data residency Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Set the api_host to the EU endpoint to comply with data residency requirements. ```php $settings = app(MixpanelSettings::class); $settings->api_host = 'https://api-eu.mixpanel.com'; $settings->save(); ``` -------------------------------- ### Test Mixpanel Blade Script Rendering Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Tests verify that the Mixpanel tracking script renders correctly based on project token settings and custom library URL configurations. ```php use JeffersonGoncalves\Mixpanel\Settings\MixpanelSettings; it('renders the tracking script when project_token is set', function () { $settings = app(MixpanelSettings::class); $settings->project_token = 'test-token-123'; $settings->save(); $view = $this->blade('@include("mixpanel::script")'); $view->assertSee('mixpanel.init("test-token-123"'); }); it('does not render the script when project_token is null', function () { $settings = app(MixpanelSettings::class); $settings->project_token = null; $settings->save(); $view = $this->blade('@include("mixpanel::script")'); $view->assertDontSee('mixpanel'); }); it('renders custom lib URL when set', function () { $settings = app(MixpanelSettings::class); $settings->project_token = 'test-token'; $settings->custom_lib_url = 'https://cdn.example.com/mixpanel.js'; $settings->save(); $view = $this->blade('@include("mixpanel::script")'); $view->assertSee('MIXPANEL_CUSTOM_LIB_URL'); $view->assertSee('https://cdn.example.com/mixpanel.js'); }); ``` -------------------------------- ### script.blade.php view for Mixpanel tracking Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Blade view that resolves MixpanelSettings from the container and conditionally renders the Mixpanel tracking scripts. Only renders when project_token is not empty; if custom_lib_url is set, defines MIXPANEL_CUSTOM_LIB_URL before the SDK loader. Uses json_encode with JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT for the config. ```blade @php $settings = app(\JeffersonGoncalves\Mixpanel\Settings\MixpanelSettings::class); @endphp @if(!empty($settings->project_token)) @if($settings->custom_lib_url) @endif @endif ``` -------------------------------- ### Set property blacklist Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Set the property_blacklist as a comma-separated string. The toJsConfig() method converts it to an array. ```php $settings = app(MixpanelSettings::class); $settings->property_blacklist = '$current_url, $initial_referrer, $referrer'; $settings->save(); // toJsConfig() output: ['property_blacklist' => ['$current_url', '$initial_referrer', '$referrer']] ``` -------------------------------- ### Test toJsConfig() Configuration Transformation Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md These tests ensure that settings are correctly cast to types expected by the JavaScript configuration, such as converting string booleans and parsing comma-separated lists. ```php it('converts track_pageview string booleans to actual booleans', function () { $settings = app(MixpanelSettings::class); $settings->track_pageview = 'true'; $config = $settings->toJsConfig(); expect($config['track_pageview'])->toBeTrue(); }); it('passes non-boolean track_pageview values as strings', function () { $settings = app(MixpanelSettings::class); $settings->track_pageview = 'url-with-path'; $config = $settings->toJsConfig(); expect($config['track_pageview'])->toBe('url-with-path'); }); it('converts property_blacklist to array', function () { $settings = app(MixpanelSettings::class); $settings->property_blacklist = '$current_url, $referrer'; $config = $settings->toJsConfig(); expect($config['property_blacklist'])->toBe(['$current_url', '$referrer']); }); it('excludes api_host from config when null', function () { $settings = app(MixpanelSettings::class); $settings->api_host = null; $config = $settings->toJsConfig(); expect($config)->not->toHaveKey('api_host'); }); ``` -------------------------------- ### Set custom library URL Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Override the default Mixpanel library URL with a custom CDN URL. ```php $settings = app(MixpanelSettings::class); $settings->custom_lib_url = 'https://cdn.example.com/mixpanel.min.js'; $settings->save(); ``` -------------------------------- ### Add new setting property to MixpanelSettings Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/resources/boost/skills/mixpanel-development/SKILL.md Add a new boolean property to the settings class. ```php public bool $record_idle_timeout_ms = false; ``` -------------------------------- ### Include Mixpanel script in Blade layout Source: https://github.com/jeffersongoncalves/laravel-mixpanel/blob/master/README.md Include the Mixpanel script in your Blade layout, typically before the closing tag. ```blade @include('mixpanel::script') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.