Today, weโll implement click tracking so you know which GPT-recommended products users actually click on. This will help refine future recommendations and power feedback loops.
๐ Step 1: Create a Click Tracking Table
php artisan make:migration create_product_clicks_table
Update the migration:
public function up()
{
Schema::create('product_clicks', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('product_id')->constrained()->onDelete('cascade');
$table->timestamp('clicked_at')->default(now());
$table->timestamps();
});
}
Then run:
php artisan migrate
๐ฅ Step 2: Define Relationships
In User.php
:
public function productClicks()
{
return $this->hasMany(\App\Models\ProductClick::class);
}
In Product.php
:
public function clicks()
{
return $this->hasMany(\App\Models\ProductClick::class);
}
๐ฏ Step 3: Create Controller for Logging Clicks
php artisan make:controller ProductClickController
In ProductClickController.php
:
use App\Models\ProductClick;
use Illuminate\Support\Facades\Auth;
public function store($productId)
{
$user = Auth::user() ?? \App\Models\User::first(); // demo user
ProductClick::create([
'user_id' => $user->id,
'product_id' => $productId,
'clicked_at' => now(),
]);
return redirect()->route('products.show', $productId); // you can customize this
}
๐ฃ Step 4: Define Route
In web.php
:
use App\Http\Controllers\ProductClickController;
Route::post('/click/{product}', [ProductClickController::class, 'store'])->name('products.click');
๐ง Step 5: Update Blade to Log Clicks
In your Blade view:
<form method="POST" action="{{ route('products.click', $product->id) }}">
@csrf
<button type="submit" class="text-blue-500 text-sm mt-3 inline-block">
View Product
</button>
</form>
โ Summary
โ Today you:
- Created a new table to track recommendation clicks
- Logged when users engage with suggested items
- Built the foundation for feedback-based AI improvements
โ Up next (Day 7): Weโll begin using click tracking to influence GPT prompts, by weighting product types the user actually engages with.