protonemedia /
laravel-analytics-event-tracking
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ProtoneMedia\AnalyticsEventTracking\Jobs; |
||
| 4 | |||
| 5 | use Illuminate\Bus\Queueable; |
||
| 6 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
| 7 | use Illuminate\Foundation\Bus\Dispatchable; |
||
| 8 | use Illuminate\Queue\InteractsWithQueue; |
||
| 9 | use Illuminate\Queue\SerializesModels; |
||
| 10 | use ProtoneMedia\AnalyticsEventTracking\Analytics\EventBroadcaster; |
||
| 11 | use TheIconic\Tracking\GoogleAnalytics\Analytics; |
||
| 12 | |||
| 13 | class SendEventToAnalytics implements ShouldQueue |
||
| 14 | { |
||
| 15 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 16 | |||
| 17 | public $event; |
||
| 18 | public ?string $clientId; |
||
| 19 | public ?string $userId; |
||
| 20 | |||
| 21 | public function __construct($event, string $clientId = null, string $userId = null) |
||
| 22 | { |
||
| 23 | $this->event = $event; |
||
| 24 | $this->clientId = $clientId; |
||
| 25 | $this->userId = $userId; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function handle(EventBroadcaster $broadcaster) |
||
| 29 | { |
||
| 30 | if ($this->clientId) { |
||
| 31 | $broadcaster->withAnalytics(fn (Analytics $analytics) => $analytics->setClientId($this->clientId)); |
||
| 32 | } |
||
| 33 | |||
| 34 | if ($this->userId) { |
||
| 35 | $broadcaster->withAnalytics(fn (Analytics $analytics) => $analytics->setUserId($this->userId)); |
||
| 36 | } |
||
| 37 | |||
| 38 | $broadcaster->handle($this->event); |
||
| 39 | } |
||
| 40 | } |
||
| 41 |