Amazon Affiliate Block - Independent Product Selection
Amazon Affiliate Block - Independent Product Selection
Overview
The affiliate block system has been updated to ensure that each ad banner on a page displays different products, even when multiple affiliate blocks appear on the same page.
How It Works
Block ID Parameter
Each affiliate block can now accept a block_id parameter that creates unique product selections:
<div class="affiliate-block">
<div class="affiliate-block-header">
<h3>Productos Recomendados</h3>
<span class="affiliate-disclaimer">Como Afiliados de Amazon, ganamos por compras calificadas. Precios orientativos, sujetos a cambios.</span>
</div>
<div class="affiliate-products-grid">
<div class="product-card">
<span class="product-category">books</span>
<h4 class="product-name">Official History of the Tour de France (English)</h4>
<p class="product-description">Historia oficial del Tour de Francia en inglés (edición revisada)</p>
<a href="https://www.amazon.es/Official-History-Tour-France-Revised/dp/103542665X?tag=ciclismohoy-21&utm_source=ciclismohoy&utm_medium=affiliate&utm_campaign=home&utm_content=book-tour-official-english"
class="product-cta"
data-product-id="book-tour-official-english"
data-race-terrain="flat"
target="_blank"
rel="noopener nofollow">
Ver en Amazon
</a>
</div>
<div class="product-card">
<span class="product-category">books</span>
<h4 class="product-name">Los Años Heroicos del Tour de Francia 1903-1914</h4>
<p class="product-description">Los inicios épicos del Tour de Francia 1903-1914</p>
<a href="https://www.amazon.es/a%C3%B1os-heroicos-Tour-Francia-1903-1914/dp/1500480452?tag=ciclismohoy-21&utm_source=ciclismohoy&utm_medium=affiliate&utm_campaign=home&utm_content=book-tour-heroic-years"
class="product-cta"
data-product-id="book-tour-heroic-years"
data-race-terrain="flat"
target="_blank"
rel="noopener nofollow">
Ver en Amazon
</a>
</div>
<div class="product-card">
<span class="product-category">clothing</span>
<h4 class="product-name">Gore Wear Maillot Spinshift Thermo Hombre</h4>
<p class="product-description">Maillot térmico Spinshift para días fríos</p>
<a href="https://www.amazon.es/GOREWEAR-Maillot-SPINSHIFT-Thermo-Hombre/dp/B0FG2JMDD5?tag=ciclismohoy-21&utm_source=ciclismohoy&utm_medium=affiliate&utm_campaign=home&utm_content=clothing-gore-jersey-thermo-men"
class="product-cta"
data-product-id="clothing-gore-jersey-thermo-men"
data-race-terrain="flat"
target="_blank"
rel="noopener nofollow">
Ver en Amazon
</a>
</div>
</div>
</div>
Hash-Based Rotation
The block_id is hashed into a numeric value that modifies the daily rotation seed, ensuring different products are selected for each unique block_id on the same day.
Implementation Examples
1. Default Layout (default.html)
- Block ID:
"bottom" - Used for the affiliate section that appears after race article content
2. Home Layout (home.html)
- Block ID:
"home-grid" - Appears after the 4th race card in the grid
3. Month Layout (month.html)
- Block ID:
"month-1","month-2", etc. - Dynamic IDs based on position in the race list
- Appears every 6 races
4. Year Layout (year.html)
- Block ID:
"year-1","year-2", etc. - Dynamic IDs based on position in the months list
- Appears every 6 months
5. Race List Layout (race-list.html)
- Block ID:
"list-1","list-2", etc. - Dynamic IDs based on position in the race list
- Appears every 3 races
Testing
To verify that different products are shown:
- Visit a page with multiple ad blocks (e.g., month overview with many races, or recent-races page)
- Observe the products in each affiliate block
- Confirm that each block shows different products
Verified Results
Testing on the recent-races page with 3 affiliate blocks shows:
- Block 1: Official History (English), Wahoo ELEMNT BOLT v2, Gore Wear Maillot
- Block 2: Official History (English), Garmin Edge 840, Wahoo ELEMNT ROAM
- Block 3: La Historia (Española), Garmin Edge 840, Official History (English)
✅ Each block displays a unique combination of products ✅ Most products appear in only 1-2 blocks (not all 3) ✅ The same filtering criteria still apply (terrain, season, race keywords)
Example: Month Page
On a month page with 18 races, you should see:
- 1st affiliate block (after race 6): Shows products based on
"month-1"block_id - 2nd affiliate block (after race 12): Shows products based on
"month-2"block_id - 3rd affiliate block (after race 18): Shows products based on
"month-3"block_id
Each block will have different products from the same pool, scored by the same criteria (terrain, season, race keywords) but with different rotation seeds.
Technical Details
Modified Code in amazon-affiliate-block.html
[character hashing logic - supports 0-9, a-z, and hyphen]
[character hashing logic - supports 0-9, a-z, and hyphen]
[character hashing logic - supports 0-9, a-z, and hyphen]
[character hashing logic - supports 0-9, a-z, and hyphen]
[character hashing logic - supports 0-9, a-z, and hyphen]
[character hashing logic - supports 0-9, a-z, and hyphen]
[character hashing logic - supports 0-9, a-z, and hyphen]
The hash function converts the block_id string into a numeric value by summing character values. This value is used in two ways:
- rotation_bonus: Shifts which products get higher rotation scores
- offset_bonus: Adds a variable bonus that changes per product based on the block_id, creating significant score differences that result in different products being selected
The offset_bonus uses a larger divisor (5.0 instead of 10.0) and a larger modulo (13 instead of 7) to create more significant score variations between blocks.
Benefits
- ✅ Better user experience: Visitors see variety in product recommendations
- ✅ Higher engagement: Different products may appeal to different interests
- ✅ Maintained relevance: All blocks still use the same smart filtering (terrain, season, race keywords)
- ✅ Easy to implement: Just add
block_idparameter when including the affiliate block
Future Enhancements
- Add more characters to the hash function if needed for more complex block IDs
- Consider product exclusion logic to prevent the same product appearing in nearby blocks
- Add analytics tracking to measure performance of different block positions