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,99 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('adsense_connections')) {
|
||||
Schema::create('adsense_connections', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('account_resource_name', 128)->nullable();
|
||||
$table->string('account_display_name', 191)->nullable();
|
||||
$table->text('encrypted_refresh_token')->nullable();
|
||||
$table->string('status', 32)->default('pending')->index();
|
||||
$table->unsignedBigInteger('connected_by_user_id')->nullable();
|
||||
$table->timestamp('connected_at')->nullable();
|
||||
$table->timestamp('last_sync_attempt_at')->nullable();
|
||||
$table->timestamp('last_successful_sync_at')->nullable();
|
||||
$table->text('last_error')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('connected_by_user_id')
|
||||
->references('id')
|
||||
->on('users')
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
if (! Schema::hasTable('adsense_entities')) {
|
||||
Schema::create('adsense_entities', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('account_resource_name', 128);
|
||||
$table->string('ad_client_resource_name', 191)->nullable();
|
||||
$table->string('type', 32);
|
||||
$table->string('resource_name', 191)->nullable();
|
||||
$table->string('reporting_dimension_id', 128);
|
||||
$table->string('display_name', 191);
|
||||
$table->boolean('active')->nullable();
|
||||
$table->timestamp('last_seen_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(
|
||||
['account_resource_name', 'type', 'reporting_dimension_id'],
|
||||
'adsense_entities_unique'
|
||||
);
|
||||
$table->index(['account_resource_name', 'type'], 'adsense_entities_account_type_idx');
|
||||
});
|
||||
}
|
||||
|
||||
if (! Schema::hasTable('adsense_daily_stats')) {
|
||||
Schema::create('adsense_daily_stats', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->date('date');
|
||||
$table->string('account_resource_name', 128);
|
||||
$table->string('dimension_type', 32);
|
||||
$table->string('dimension_key', 128);
|
||||
$table->string('dimension_label', 191)->nullable();
|
||||
$table->string('currency_code', 8)->nullable();
|
||||
$table->unsignedBigInteger('page_views')->nullable();
|
||||
$table->unsignedBigInteger('ad_requests')->nullable();
|
||||
$table->unsignedBigInteger('matched_ad_requests')->nullable();
|
||||
$table->unsignedBigInteger('impressions')->nullable();
|
||||
$table->unsignedBigInteger('clicks')->nullable();
|
||||
$table->decimal('estimated_earnings', 16, 6)->nullable();
|
||||
$table->decimal('page_views_ctr', 12, 8)->nullable();
|
||||
$table->decimal('page_views_rpm', 16, 6)->nullable();
|
||||
$table->decimal('ad_requests_coverage', 12, 8)->nullable();
|
||||
$table->decimal('ad_requests_ctr', 12, 8)->nullable();
|
||||
$table->decimal('ad_requests_rpm', 16, 6)->nullable();
|
||||
$table->decimal('impressions_ctr', 12, 8)->nullable();
|
||||
$table->decimal('impressions_rpm', 16, 6)->nullable();
|
||||
$table->decimal('cost_per_click', 16, 6)->nullable();
|
||||
$table->timestamp('last_synced_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(
|
||||
['account_resource_name', 'date', 'dimension_type', 'dimension_key'],
|
||||
'adsense_daily_stats_unique'
|
||||
);
|
||||
$table->index(
|
||||
['account_resource_name', 'dimension_type', 'date'],
|
||||
'adsense_daily_stats_lookup_idx'
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('adsense_daily_stats');
|
||||
Schema::dropIfExists('adsense_entities');
|
||||
Schema::dropIfExists('adsense_connections');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user