Skip to main content
The Recommendations module provides methods to retrieve personalized product recommendations based on various strategies.

Getting Started

The recommendations module is available on your Constructor.io client instance:
const ConstructorioClient = require('@constructor-io/constructorio-client-javascript');

const constructorio = new ConstructorioClient({
  apiKey: 'YOUR_API_KEY',
});

// Access the recommendations module
constructorio.recommendations.getRecommendations('best-sellers');

Methods

getRecommendations

Retrieve personalized recommendations for a specific pod.
A “pod” is a recommendation strategy configured in your Constructor.io dashboard. Each pod has a unique identifier and can use different algorithms (e.g., best sellers, trending, personalized, item-to-item).
constructorio.recommendations.getRecommendations('best-sellers')
  .then((response) => {
    console.log(response.response.results);
  });

Parameters

podId
string
required
The unique identifier for the recommendation pod (configured in your Constructor.io dashboard)
parameters
object
Additional parameters to refine results
networkParameters
object
Parameters relevant to the network request

Response Structure

{
  "response": {
    "results": [
      {
        "matched_terms": ["recommendation"],
        "data": {
          "id": "product-123",
          "title": "Blue T-Shirt",
          "url": "/products/product-123",
          "image_url": "https://example.com/image.jpg",
          "price": 29.99
        },
        "result_id": "abc123-xyz789"
      }
    ],
    "total_num_results": 10,
    "pod": {
      "id": "best-sellers",
      "display_name": "Best Sellers"
    }
  },
  "result_id": "abc123-xyz789",
  "request": {...}
}
Each result item includes a result_id field that should be used when tracking user interactions.

Recommendation Strategies

Display your top-performing products:
constructorio.recommendations.getRecommendations('best-sellers', {
  numResults: 12,
  filters: {
    category: 'clothing'
  }
});

Common Use Cases

1

Homepage Recommendations

Display personalized or trending products:
async function loadHomeRecommendations() {
  const response = await constructorio.recommendations.getRecommendations('homepage-recs', {
    numResults: 12
  });
  
  displayProducts(response.response.results);
}
2

Product Detail Page

Show similar or complementary products:
async function loadProductRecommendations(currentProductId) {
  const [similar, boughtTogether] = await Promise.all([
    constructorio.recommendations.getRecommendations('similar', {
      itemIds: currentProductId,
      numResults: 6
    }),
    constructorio.recommendations.getRecommendations('bought-together', {
      itemIds: currentProductId,
      numResults: 4
    })
  ]);
  
  displaySimilarProducts(similar.response.results);
  displayBoughtTogether(boughtTogether.response.results);
}
3

Cart Page

Suggest additional items based on cart contents:
async function loadCartRecommendations(cartItemIds) {
  const response = await constructorio.recommendations.getRecommendations('cart-recs', {
    itemIds: cartItemIds,
    numResults: 8
  });
  
  displayCartRecommendations(response.response.results);
}

Events

The recommendations module dispatches custom events on the browser window when requests complete:
window.addEventListener('cio.client.recommendations.getRecommendations.completed', (event) => {
  // event.detail contains the response data
  console.log(event.detail);
  console.log('Pod ID:', event.detail.response.pod.id);
}, false);

Tracking Recommendations

Always track when users interact with recommendations:
function handleRecommendationClick(product) {
  // Navigate to product
  window.location.href = product.data.url;
  
  // Track the click
  constructorio.tracker.trackRecommendationClick(
    product.data.id,
    { 
      result_id: product.result_id,
      pod_id: 'best-sellers'
    }
  );
}

Build docs developers (and LLMs) love