This is a preview of unreleased docs from main. View the published docs
Skip to main content

Recommendations

<allegro-recommendations> is a web component that fetches ranked article recommendations for the current reader via allegro.recommendations and renders them as a "Read Next" or "More Like This" list, reporting clicks automatically. The common case needs no JavaScript from the publisher — just place the tag.

When no recommendations are available — no engine configured for the tenant, the engine unreachable, or the SDK call fails — the component renders nothing at all rather than an empty container.

Usage​

<allegro-recommendations></allegro-recommendations>

With custom attributes:

<allegro-recommendations
limit="4"
heading="Read Next"
layout="grid"
></allegro-recommendations>

Attributes​

AttributeTypeDefaultDescription
limitnumber(empty)How many articles to request. Defaults to 6 upstream; 24 is the maximum.
max-age-daysnumber(empty)Excludes articles published more than this many days ago. Defaults to no cap.
pathtext(empty)Article to anchor the recommendations on. Defaults to the current page path.
headingtext(empty)Heading shown above the list. When omitted, no heading is rendered.
layoutselectlistLayout for the rendered items: list or grid.
show-placeholderbooleantrueWhether to reserve space with placeholder rows while loading. Set to false to render nothing until the items arrive.
tracking-datatext(empty)JSON object of custom data merged into every tracked event, e.g. "{'campaign': 'sidebar'}".

Loading Placeholder​

While the request is in flight the component renders a grid of gray placeholder rows matching the requested limit and layout, and carries aria-busy="true" until the request settles. This reserves the space the items will occupy so the surrounding page does not shift when they arrive.

<allegro-recommendations show-placeholder="false"></allegro-recommendations>

Set show-placeholder="false" for placements where an empty gap is preferable to a visible skeleton — a sidebar that should collapse when the engine returns nothing, for instance. The component then stays empty until the items render.

Click Attribution​

Each rendered item's link click calls allegro.recommendations.trackClick(item) with the exact item object the component rendered from, so attribution is resolved by identity rather than by path matching.

Shadow Parts​

For styling beyond what the CSS variables make available, elements can be targeted directly with the CSS ::part() selector.

allegro-recommendations::part(item-title) {
text-transform: uppercase;
}
PartDescription
wrapperWrapper around the heading and item list.
headingThe heading element, when heading is set.
itemsThe <ul> of rendered items.
itemEach <li> item wrapper.
item-linkEach item's <a> element.
item-imageEach item's <img> element, when the item has one.
item-titleEach item's title text.

CSS Variables​

All visual properties are exposed as CSS custom properties so the component can be themed from the host page without piercing the shadow DOM.

allegro-recommendations {
--recommendations--grid--columns: 4;
--recommendations--item-title--font-weight: 700;
}
VariableDefaultDescription
--recommendations--font-familysystem-ui, sans-serifFont family for the component.
--recommendations--heading--color#111Heading text color.
--recommendations--heading--font-size1.125remHeading font size.
--recommendations--heading--font-weight700Heading font weight.
--recommendations--items--gap1remGap between rendered items.
--recommendations--grid--columns3Number of columns in grid layout.
--recommendations--grid--columns-mobile1Number of columns in grid layout below 40em.
--recommendations--item-image--aspect-ratio16 / 9Aspect ratio of each item image in grid layout, so every image is cropped to a uniform height regardless of its source dimensions.
--recommendations--item-image--border-radius0.375remItem image border radius.
--recommendations--item-image--list-size4.5remItem image size in list layout.
--recommendations--item-title--color#111Item title text color.
--recommendations--item-title--font-size0.9375remItem title font size.
--recommendations--item-title--font-weight600Item title font weight.
  • Recommendations guide — How ranking works, the allegro.recommendations API, and click attribution details.