Recommendations

Marketing Cloud Personalization Recommendations uses a default gear to fetch recommendations based on the current user and selected recipe. Ultimately, the Recommendations service supplies all recommendations provided to the applicable gear component contexts in gears.

The Recommendations gear enables you to configure a campaign template to control what a business user can configure to drive recommendations for the template.

Usage 

To use and configure the Recommendations gear in a campaign template, do the following.

  1. Add import { RecommendationsConfig, recommend } from "recs"; to your template’s server-side TypeScript. Optionally, to only return item IDs instead of full items, import recommendIdsOnly instead of recommend.

  2. Add a RecommendationsConfig property to your template, and determine what to restrict from the business user, if anything.

    • No restrictions:

      1recsConfig: RecommendationsConfig = new RecommendationsConfig();
    • Restrict business users to be able to recommend only a specific type of catalog items:

      1recsConfig: RecommendationsConfig = new RecommendationsConfig().restrictItemType("Product");
    • Restrict business users to a specific maximum number of recommendations:

      1recsConfig: RecommendationsConfig = new RecommendationsConfig().restrictMaxResults(4);
    • Restrict business users to both a specific type of catalog item and a specific maximum number of recommendations:

      1recsConfig: RecommendationsConfig = new RecommendationsConfig()
      2  .restrictItemType("Product")
      3  .restrictMaxResults(4);
    • Restrict business users to a specific type of catalog item and programmatically override an on-page anchor that is used by the recipe:

      1recsConfig: RecommendationsConfig = new RecommendationsConfig()
      2  .restrictItemType("Product")
      3  .overrideOnPageAnchor(itemId, itemType);
  3. Use the recommend function to use the configuration property of type RecommendationsConfig you added.

Example Templates 

The following example depicts the usage of the Recommendations gear in a campaign template.

1import { RecommendationsConfig, recommend } from "recs";
2
3export class ExampleRecommendationsTemplate implements CampaignTemplateComponent {
4  recsConfig: RecommendationsConfig = new RecommendationsConfig().restrictItemType("Product");
5
6  run(context: CampaignComponentContext) {
7    return {
8      products: recommend(context, this.recsConfig),
9    };
10  }
11}

You can also use the recommendIdsOnly function to return only the Item IDs in order of relevance, as shown in the following example.

1import { RecommendationsConfig, recommendIdsOnly } from "recs";
2
3export class ExampleRecommendationsTemplate implements CampaignTemplateComponent {
4  recsConfig: RecommendationsConfig = new RecommendationsConfig().restrictItemType("Product");
5
6  run(context: CampaignComponentContext) {
7    return {
8      products: recommendIdsOnly(context, this.recsConfig),
9    };
10  }
11}

The following example shows the overrideOnPageAnchor method using a Product from a Triggered Campaign context as an on-page anchor for the recipe.

1export class ExampleRecommendationsTemplate implements CampaignTemplateComponent {
2  recsConfig: RecommendationsConfig = new RecommendationsConfig().restrictItemType("Product");
3
4  run(context: CampaignComponentContext) {
5    if (context?.trigger) {
6      const triggerContext = context.trigger as CatalogTrigger;
7
8      if (triggerContext?.itemIdsByType?.["Product"]?.length) {
9        const productId = triggerContext.itemIdsByType["Product"][0];
10        this.recsConfig.overrideOnPageAnchor(productId, "Product");
11      }
12    }
13
14    return {
15      products: recommend(context, this.recsConfig),
16    };
17  }
18}

Locales 

If a dataset has locales configured, the Recommendations gear returns items specific to the user’s locale. If a user doesn’t have a locale preference, it returns items specific to the dataset’s default locale. Any item returned from the Recommendations API is translated into the user’s language, provided a locale item specific to that language exists.