Skip to main content
This guide shows how to inject sponsored products at fixed positions in your using a Smart Group. The example below uses a Recommend trending-items model as the source, but the same pattern works with search or external sources. The steps walk through both the API and Merchandising Studio paths. Before you begin, review the Composition API requirements.
Create the composition with the Update and insert composition endpoint, then apply the behavior defined below. To scope the behavior to a specific , category, or context, send the same behavior inside a composition rule’s consequence.behavior with the Update and insert composition rule endpoint.
1

Configure the main organic results

Set the main organic results to your products index. To narrow them to in-stock items, add a filter on the inStock attribute:
JSON
{
  "behavior": {
    "injection": {
      "main": {
        "source": {
          "search": {
            "index": "products",
            "params": {
              "filters": "inStock:true"
            }
          }
        }
      }
    }
  }
}
2

Add a recommend Smart Group of trending items

Add a Smart Group by appending an entry to injection.injectedItems, using source.recommend to populate it from the trending-items Recommend model. The position and length fields control where the group appears in your organic results and how many items it includes.
JSON
{
  "behavior": {
    "injection": {
      "main": {
        "source": {
          "search": {
            "index": "products",
            "params": {
              "filters": "inStock:true"
            }
          }
        }
      },
      "injectedItems": [
        {
          "key": "trending-products",
          "source": {
            "recommend": {
              "indexName": "products",
              "model": "trending-items",
              "threshold": 50,
              "queryParameters": {
                "filters": "inStock:true"
              }
            }
          },
          "position": 0,
          "length": 4
        }
      ]
    }
  }
}

Sorting strategy

Sort the organic results by price in descending order, while keeping the sponsored products in place.
JSON
{
  "behavior": {
    "sortingStrategy": {
      "Price descending": "products_price_descending"
    },
    "injection": {
      "main": {
        "source": {
          "search": {
            "index": "products",
            "params": {
              "filters": "inStock:true"
            }
          }
        }
      },
      "injectedItems": [
        {
          "key": "trending-products",
          "source": {
            "recommend": {
              "indexName": "products",
              "model": "trending-items",
              "threshold": 50,
              "queryParameters": {
                "filters": "inStock:true"
              }
            }
          },
          "position": 0,
          "length": 4
        }
      ]
    }
  }
}

See also

Last modified on June 4, 2026