From 837cce8a64520911f88854bbf0cb11a8c6ff394d Mon Sep 17 00:00:00 2001 From: adhityairvan Date: Fri, 19 Aug 2022 23:10:52 +0700 Subject: [PATCH] move mixpanel config to its own publishable config file --- README.md | 15 ++++++++------- config/mixpanel.php | 11 +++++++++++ config/services.php | 13 ------------- resources/views/partials/mixpanel.blade.php | 4 ++-- src/LaravelMixpanel.php | 12 ++++++------ src/Providers/Service.php | 12 ++++++++++-- 6 files changed, 37 insertions(+), 30 deletions(-) create mode 100644 config/mixpanel.php delete mode 100644 config/services.php diff --git a/README.md b/README.md index 9d2d733..9f25c62 100644 --- a/README.md +++ b/README.md @@ -46,20 +46,21 @@ We like to thank the following sponsors for their generosity. Please take a mome ## Configuration ### Default Values -- `services.mixpanel.host`: pulls the 'MIXPANEL_HOST' value from your `.env` +- `mixpanel.host`: pulls the 'MIXPANEL_HOST' value from your `.env` file. -- `services.mixpanel.token`: pulls the 'MIXPANEL_TOKEN' value from your `.env` +- `mixpanel.token`: pulls the 'MIXPANEL_TOKEN' value from your `.env` file. -- `services.mixpanel.enable-default-tracking`: (default: true) enable or disable +- `mixpanel.enable-default-tracking`: (default: true) enable or disable Laravel user event tracking. -- `services.mixpanel.consumer`: (default: socket) set the Guzzle adapter you +- `mixpanel.consumer`: (default: socket) set the Guzzle adapter you want to use. -- `services.mixpanel.connect-timeout`: (default: 2) set the number of seconds +- `mixpanel.connect-timeout`: (default: 2) set the number of seconds after which connections timeout. -- `services.mixpanel.timeout`: (default: 2) set the number of seconds after +- `mixpanel.timeout`: (default: 2) set the number of seconds after which event tracking times out. -- `services.mixpanel.data_callback_class`: (default: null) manipulate the data +- `mixpanel.data_callback_class`: (default: null) manipulate the data being passed back to mixpanel for the track events. +Mixpanel config can be published and customized using `php artisan vendor:publish --tag=mixpanel-config` ## Upgrade Notes ### Version 0.7.0 for Laravel 5.5 diff --git a/config/mixpanel.php b/config/mixpanel.php new file mode 100644 index 0000000..0aa4922 --- /dev/null +++ b/config/mixpanel.php @@ -0,0 +1,11 @@ + env("MIXPANEL_HOST"), + 'token' => env('MIXPANEL_TOKEN'), + 'enable-default-tracking' => true, + 'consumer' => 'socket', + 'connect-timeout' => 2, + 'timeout' => 2, + "data_callback_class" => null, +]; \ No newline at end of file diff --git a/config/services.php b/config/services.php deleted file mode 100644 index c5610d8..0000000 --- a/config/services.php +++ /dev/null @@ -1,13 +0,0 @@ - [ - 'host' => env("MIXPANEL_HOST"), - 'token' => env('MIXPANEL_TOKEN'), - 'enable-default-tracking' => true, - 'consumer' => 'socket', - 'connect-timeout' => 2, - 'timeout' => 2, - "data_callback_class" => null, - ] -]; diff --git a/resources/views/partials/mixpanel.blade.php b/resources/views/partials/mixpanel.blade.php index bc0b8f0..72a3188 100644 --- a/resources/views/partials/mixpanel.blade.php +++ b/resources/views/partials/mixpanel.blade.php @@ -1,8 +1,8 @@ diff --git a/src/LaravelMixpanel.php b/src/LaravelMixpanel.php index e3662da..296e8c3 100644 --- a/src/LaravelMixpanel.php +++ b/src/LaravelMixpanel.php @@ -19,20 +19,20 @@ public function __construct(Request $request, array $options = []) { $this->callbackResults = []; $this->defaults = [ - 'consumer' => config('services.mixpanel.consumer', 'socket'), - 'connect_timeout' => config('services.mixpanel.connect-timeout', 2), - 'timeout' => config('services.mixpanel.timeout', 2), + 'consumer' => config('mixpanel.consumer', 'socket'), + 'connect_timeout' => config('mixpanel.connect-timeout', 2), + 'timeout' => config('mixpanel.timeout', 2), ]; - if (config('services.mixpanel.host')) { - $this->defaults["host"] = config('services.mixpanel.host'); + if (config('mixpanel.host')) { + $this->defaults["host"] = config('mixpanel.host'); } $this->request = $request; parent::__construct( - config('services.mixpanel.token'), + config('mixpanel.token'), array_merge($this->defaults, $options) ); } diff --git a/src/Providers/Service.php b/src/Providers/Service.php index 3988a3a..bda060f 100644 --- a/src/Providers/Service.php +++ b/src/Providers/Service.php @@ -37,17 +37,25 @@ public function boot() __DIR__ . '/../../public' => public_path(), ], 'assets'); - if (config('services.mixpanel.enable-default-tracking')) { + if (config('mixpanel.enable-default-tracking')) { $authModel = config('auth.providers.users.model') ?? config('auth.model'); $this->app->make($authModel)->observe(new LaravelMixpanelUserObserver()); } + + if ($this->app->runningInConsole()) { + + $this->publishes([ + __DIR__ . '/../../config/mixpanel.php' => config_path('blogpackage.php'), + ], 'mixpanel-config'); + + } } public function register() { parent::register(); - $this->mergeConfigFrom(__DIR__ . '/../../config/services.php', 'services'); + $this->mergeConfigFrom(__DIR__ . '/../../config/mixpanel.php', 'mixpanel'); $this->commands(Publish::class); $this->app->singleton('mixpanel', LaravelMixpanel::class); }