tindertrack-e-commerce-clone / deals-script.js
ebaycom's picture
https://www.amazon.com/gp/goldbox?promotionsSearchLastSeenAsin=B0BYSWG9RH&promotionsSearchStartIndex=30&promotionsSearchPageSize=60&linkCode=ll2&tag=tinder0001-20&linkId=b1e32d38bc34fbc719b689cfba634fc5&language=en_US&ref_=as_li_ss_tl clone the above URL into selling landing page, add the tracking:StoreID: tinder0001-20 to every single link for affiliate commission, add pagination, products details names, images, description, shipping info, reviews when available make it updates hourly from amazon data base, Smart professional coding, Icons, higher technologies stricture Modern architecture fluid design
627a319 verified
Raw History Blame Contribute Delete
8.07 kB
// Amazon Deals Page Functionality
document.addEventListener('DOMContentLoaded', function() {
// Simulate loading deals from Amazon API
loadDeals();
// Countdown timer for deal refresh
startCountdown();
// Initialize tooltips
feather.replace();
});
function loadDeals() {
// In a real implementation, this would fetch from an API endpoint
// that pulls Amazon deals data with our affiliate tag
const dealsContainer = document.getElementById('deals-container');
dealsContainer.innerHTML = ''; // Clear existing
// Sample data - in real app this would come from API
const sampleDeals = [
{
id: 'B0BYSWG9RH',
title: 'Wireless Noise Cancelling Headphones',
image: 'http://static.photos/technology/640x360/1',
price: 89.99,
originalPrice: 149.99,
discount: 40,
rating: 4.5,
reviewCount: 1280,
isPrime: true,
shipping: 'FREE delivery',
dealEnds: '2023-12-31T23:59:59'
},
{
id: 'B08L5V9RV7',
title: 'Smart Watch with Fitness Tracker',
image: 'http://static.photos/technology/640x360/2',
price: 129.99,
originalPrice: 199.99,
discount: 35,
rating: 4.2,
reviewCount: 876,
isPrime: true,
shipping: 'FREE delivery',
dealEnds: '2023-12-31T23:59:59'
},
{
id: 'B07VGRJDFY',
title: '4K Smart TV 55"',
image: 'http://static.photos/technology/640x360/3',
price: 399.99,
originalPrice: 599.99,
discount: 33,
rating: 4.7,
reviewCount: 2543,
isPrime: true,
shipping: 'FREE delivery',
dealEnds: '2023-12-31T23:59:59'
},
{
id: 'B08N5KWB9H',
title: 'Robot Vacuum Cleaner',
image: 'http://static.photos/technology/640x360/4',
price: 199.99,
originalPrice: 349.99,
discount: 43,
rating: 4.3,
reviewCount: 1120,
isPrime: true,
shipping: 'FREE delivery',
dealEnds: '2023-12-31T23:59:59'
},
{
id: 'B08L5V9RV7',
title: 'Air Fryer 5.8QT',
image: 'http://static.photos/home/640x360/5',
price: 79.99,
originalPrice: 129.99,
discount: 38,
rating: 4.6,
reviewCount: 4321,
isPrime: true,
shipping: 'FREE delivery',
dealEnds: '2023-12-31T23:59:59'
},
{
id: 'B08N5KWB9H',
title: 'Bluetooth Speaker Waterproof',
image: 'http://static.photos/technology/640x360/6',
price: 39.99,
originalPrice: 69.99,
discount: 43,
rating: 4.4,
reviewCount: 876,
isPrime: true,
shipping: 'FREE delivery',
dealEnds: '2023-12-31T23:59:59'
}
];
// Render deals
dealsContainer.innerHTML = sampleDeals.map(deal => `
<div class="deal-card bg-white rounded-lg shadow-sm overflow-hidden hover:shadow-md transition-shadow border border-gray-200" data-product-id="${deal.id}">
<div class="relative">
<a href="/product/${deal.id}?StoreID=tinder0001-20">
<img src="${deal.image}" alt="${deal.title}" class="w-full h-48 object-contain p-4">
</a>
<div class="absolute top-2 left-2 bg-red-600 text-white text-xs font-bold px-2 py-1 rounded">
${deal.discount}% off
</div>
${deal.isPrime ?
'<div class="absolute top-2 right-2"><span class="bg-amazon text-black text-xs font-bold px-2 py-1 rounded">Prime</span></div>'
: ''}
<div class="absolute bottom-2 right-2">
<button class="w-10 h-10 bg-white rounded-full shadow flex items-center justify-center hover:bg-gray-100">
<i data-feather="heart" class="w-4 h-4 text-gray-600"></i>
</button>
</div>
</div>
<div class="p-4">
<a href="/product/${deal.id}?StoreID=tinder0001-20" class="block">
<h3 class="text-sm font-medium text-gray-900 mb-1 line-clamp-2">${deal.title}</h3>
<div class="flex items-center mb-1">
<div class="flex text-yellow-400">
${Array(Math.floor(deal.rating)).fill().map(() =>
'<i data-feather="star" class="w-3 h-3 fill-current"></i>'
).join('')}
${deal.rating % 1 >= 0.5 ?
'<i data-feather="star" class="w-3 h-3 fill-current"></i>' : ''}
</div>
<span class="text-xs text-gray-600 ml-1">(${deal.reviewCount})</span>
</div>
<div class="flex items-end mb-1">
<span class="text-lg font-bold text-primary">$${deal.price.toFixed(2)}</span>
<span class="text-xs text-gray-500 line-through ml-2">$${deal.originalPrice.toFixed(2)}</span>
</div>
<div class="text-xs text-green-600">${deal.shipping}</div>
</a>
<button class="mt-3 w-full bg-primary hover:bg-primary-dark text-white text-sm font-medium py-2 px-4 rounded">
Add to Cart
</button>
</div>
</div>
`).join('');
// Initialize tracking for new elements
initTracking();
}
function startCountdown() {
let seconds = 60 * 60; // 1 hour countdown
const countdownElement = document.getElementById('countdown');
const timer = setInterval(() => {
seconds--;
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
countdownElement.textContent = `${minutes}:${remainingSeconds < 10 ? '0' + remainingSeconds : remainingSeconds}`;
if (seconds <= 0) {
clearInterval(timer);
loadDeals(); // Refresh deals
startCountdown(); // Restart timer
}
}, 1000);
}
// In a real implementation, this would be an API call to get fresh deals
function refreshDeals() {
console.log('Refreshing deals from Amazon API...');
// This would make a fetch request to your backend API
// which would then make requests to Amazon's API with your affiliate tag
// and return the data formatted for your frontend
// Example of what the API call might look like:
/*
fetch('/api/amazon-deals?StoreID=tinder0001-20')
.then(response => response.json())
.then(data => {
renderDeals(data);
})
.catch(error => {
console.error('Error fetching deals:', error);
});
*/
}
// Initialize tracking for all links with StoreID
function initTracking() {
document.querySelectorAll('a[href*="StoreID=tinder0001-20"]').forEach(link => {
link.addEventListener('click', trackClick);
});
}
function trackClick(e) {
// In a real implementation, this would send to your analytics
const productId = this.closest('[data-product-id]')?.getAttribute('data-product-id');
const url = this.href;
console.log(`Tracking click: ${url} for product ${productId}`);
// Example tracking payload
const trackingData = {
storeId: 'tinder0001-20',
productId: productId || null,
url: url,
timestamp: new Date().toISOString(),
eventType: 'deal_click'
};
// In a real app, this would be sent to your backend
localStorage.setItem('lastTracking', JSON.stringify(trackingData));
}