Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions config/mixpanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'host' => env("MIXPANEL_HOST"),
'token' => env('MIXPANEL_TOKEN'),
'enable-default-tracking' => true,
'consumer' => 'socket',
'connect-timeout' => 2,
'timeout' => 2,
"data_callback_class" => null,
];
13 changes: 0 additions & 13 deletions config/services.php

This file was deleted.

4 changes: 2 additions & 2 deletions resources/views/partials/mixpanel.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script src="{{ asset('genealabs-laravel-mixpanel/js/mixpanel.js') }}"></script>
<script>
if ("{{ config('services.mixpanel.token') }}" == "") {
if ("{{ config('mixpanel.token') }}" == "") {
console.error('Mixpanel for Laravel: You must declare the env variable MIXPANEL_TOKEN!');
}

mixpanel.init("{{ config('services.mixpanel.token') }}");
mixpanel.init("{{ config('mixpanel.token') }}");
</script>
12 changes: 6 additions & 6 deletions src/LaravelMixpanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down
12 changes: 10 additions & 2 deletions src/Providers/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down