Searchstax- ExternalPromotions-Widget React


The SearchStax Site Search solution offers an external-promotions widget to assist with your React and Next.js custom search pages.

The SearchstaxExternalPromotionsWidget displays external promotions fetched from the API.

Usage

<SearchstaxExternalPromotionsWidget />

searchExternalPromotionsTemplate

Renders custom promotions UI.

Receives:

  • externalPromotionsData – Promotions data
  • trackClick – Handles click tracking

Example

function searchExternalPromotionsTemplate(
    externalPromotionsData: null | ISearchstaxExternalPromotionsData,
    trackClick: (externalPromotion: IExternalPromotion, event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => void
  ) {
    return (
      <>
        {externalPromotionsData &&
          externalPromotionsData?.searchExecuted &&
          externalPromotionsData?.hasExternalPromotions &&
          externalPromotionsData.externalPromotions.map((externalPromotion) => (
            <div className="searchstax-external-promotion searchstax-search-result" key={externalPromotion.id}>
              <div className="icon-elevated"></div>
              {externalPromotion.url && (
                <a
                  href={externalPromotion.url}
                  onClick={(event) => {
                    trackClick(externalPromotion, event);
                  }}
                  className="searchstax-result-item-link"
                ></a>
              )}
              <div className="searchstax-search-result-title-container">
                <span className="searchstax-search-result-title">{externalPromotion.name}</span>
              </div>
              {externalPromotion.description && (
                <p className="searchstax-search-result-description searchstax-search-result-common">
                  {" "}
                  {externalPromotion.description}{" "}
                </p>
              )}
              {externalPromotion.url && (
                <p className="searchstax-search-result-description searchstax-search-result-common">
                  {" "}
                  {externalPromotion.url}{" "}
                </p>
              )}
            </div>
          ))}
      </>
    );
  }
<SearchstaxExternalPromotionsWidget
                searchExternalPromotionsTemplate={searchExternalPromotionsTemplate}
              ></SearchstaxExternalPromotionsWidget>

Questions?

Do not hesitate to contact the SearchStax Support Desk.