Today weβll close the loop: using click data to help GPT make smarter, more personalized product recommendations based on what users actually engage with.
π§ Step 1: Modify ProductRecommendationService
to include click trends
Update your recommend()
method to include clicked product info:
$clickedProducts = $user->productClicks()
->with('product')
->latest('clicked_at')
->take(5)
->get()
->pluck('product')
->filter()
->map(fn ($p) => [
'name' => $p->name,
'description' => $p->description,
'category' => $p->category,
])
->toArray();
π‘ Step 2: Enhance GPT prompt with clicks
Modify the prompt inside recommend()
:
$viewed = ... // same as before
$clicked = $clickedProducts;
$messages = [
[
'role' => 'user',
'content' => 'Here is what the user viewed: ' . json_encode($viewed)
],
[
'role' => 'user',
'content' => 'Here is what the user clicked: ' . json_encode($clicked)
],
[
'role' => 'user',
'content' => 'Suggest 5 relevant product ideas based on both viewing and clicking behavior.'
],
];
Call GPT as before, using the same function-calling structure.
π§ͺ Optional: Add Click Weighting (Advanced)
You could improve further by:
- Giving more importance to clicked products
- Tracking click frequency and recency
- Segmenting user interest profiles
But for now, just adding click data into the prompt helps GPT tailor results better.
β Summary
β Today you:
- Pulled the userβs most-clicked products
- Used that feedback to enrich GPT prompts
- Moved from static to adaptive, personalized suggestions
β Up next (Day 8): Weβll cache GPT responses to reduce API calls and boost performance, while keeping results fresh.