Add a read-only Google AdSense analytics module for admins.
Connect AdSense over OAuth, sync entities and daily reports locally, and show placement performance in the admin panel without calling the Management API from public pages.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\AdsenseConnection;
|
||||
use App\Services\Adsense\AdsenseSyncService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
final class SyncAdsenseJob implements ShouldBeUnique, ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithQueue;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
public int $tries = 1;
|
||||
|
||||
public int $timeout = 180;
|
||||
|
||||
public int $uniqueFor = 600;
|
||||
|
||||
public function __construct(
|
||||
public readonly int $connectionId,
|
||||
public readonly string $from,
|
||||
public readonly string $to,
|
||||
public readonly bool $entitiesOnly = false,
|
||||
) {}
|
||||
|
||||
public function uniqueId(): string
|
||||
{
|
||||
return (string) $this->connectionId;
|
||||
}
|
||||
|
||||
public function handle(AdsenseSyncService $sync): void
|
||||
{
|
||||
$connection = AdsenseConnection::query()->find($this->connectionId);
|
||||
if ($connection === null || ! $connection->hasRefreshToken()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sync->sync(
|
||||
$connection,
|
||||
Carbon::parse($this->from)->startOfDay(),
|
||||
Carbon::parse($this->to)->startOfDay(),
|
||||
$this->entitiesOnly,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user