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:

  1. Visit a page with multiple ad blocks (e.g., month overview with many races, or recent-races page)
  2. Observe the products in each affiliate block
  3. 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:

  1. rotation_bonus: Shifts which products get higher rotation scores
  2. 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

  1. Better user experience: Visitors see variety in product recommendations
  2. Higher engagement: Different products may appeal to different interests
  3. Maintained relevance: All blocks still use the same smart filtering (terrain, season, race keywords)
  4. Easy to implement: Just add block_id parameter 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

Productos Recomendados

Como Afiliados de Amazon, ganamos por compras calificadas. Precios orientativos, sujetos a cambios.
books

La Historia Oficial del Tour de Francia (Edición Española)

Historia oficial del Tour de Francia en español

Ver en Amazon
books

Paris-Roubaix: Un Viaje por el Infierno del Norte

La mítica carrera de los adoquines del norte de Francia

Ver en Amazon
books

Official History of the Tour de France (English)

Historia oficial del Tour de Francia en inglés (edición revisada)

Ver en Amazon