Here is my code:
<?php
namespace App\Services;
use Mixpanel\Mixpanel;
use App\Models\User;
use Illuminate\Support\Facades\Config;
use Illuminate\Contracts\Auth\Authenticatable;
class MixpanelService
{
private \Mixpanel $mixpanel;
public function __construct()
{
$this->mixpanel = \Mixpanel::getInstance(config('services.mix_panel.token'), [
'host'=>'api-eu.mixpanel.com',
]);
}
public function addUser(Authenticatable $user)
{
$this->mixpanel->people->set($user->id, [
'$first_name' => $user->name,
'$email' =>$user->email,
], $ip=0);
}
}
I followed this tutorial, https://www.youtube.com/watch?v=Ojl-SXVzCTQ&t=432s at minute 10:43 I followed his code, but he didn't show what was in line 1 to 5
Can anybody help me?
Hey this is Rishi from Mixpanel Support. While I'm not as familiar with Laravel, the likely situation is that the job itself is creating a process that is either not being terminated (or at least not in a way that the SDK picks up) and the queue is not flushed so you may be able to fix this by calling flush() and people->flush() to send the data.
To clarify, the PHP SDK queues data instead of sending a request each time you call track or send a people update, and by default the queue flushes when the script is terminated. In this case it's possible the job is an ongoing process that we aren't picking up as being terminated, and the flush function is therefore never called. You can, however, call flush() manually (you will want to call both methods for event and profile updates) when it makes sense in your code.
A further debugging step would be to enable the debugging flag in the initialization which will log if the people->set call is being made. If the call is being logged and flush() isn't causing the data to appear in your project then I'd recommend double checking that the project you are sending to is EU based and that the token when initializing matches. If you continue to have issues feel free to reach out to us at http://mixpanel.com/get-support and we'd be happy to investigate any debugging logs you may have.