Action in the Session API context means fetching recommendations for a specific view. For example when a visitor navigates from the front page to a product view you would most likely fetch recommendations related to a product. This would be considered as an Action. Setting the cart contents however would not be considered as action.

interface Action {
    addAffinity(
        affinity: undefined | Record<string, string[]>,
        options?: AffinityOptions,
    ): Action;
    load(flags?: RecommendationRequestFlags): Promise<ActionResponse>;
    setCart(cart: undefined | Cart): Action;
    setCategories(categories: string[]): Action;
    setCategoryIds(categoryIds: string[]): Action;
    setCustomer(customer: undefined | PushedCustomer): Action;
    setCustomFields(customFields: Record<string, string[]>): Action;
    setOrder(order: WebsiteOrder): Action;
    setPageType(pageType: PageType): Action;
    setParentCategoryIds(parentCategoryIds: string[]): Action;
    setPlacements(placements: string[]): Action;
    setProduct(product: string | Product): Action;
    setProducts(products: (string | Product)[]): Action;
    setRef(productId: string, reference: string): Action;
    setRestoreLink(restoreLink: string): Action;
    setSearchTerms(searchTerms: string[]): Action;
    setTags(tags: string[]): Action;
    setVariation(variation: undefined | string): Action;
    update(): unknown;
}

Methods

  • Sets the affinity signals for the current action. Subsequent invocations will be merged with the previous ones.

    Parameters

    • affinity: undefined | Record<string, string[]>
    • Optionaloptions: AffinityOptions

    Returns Action

  • Sets the information about the user's current shopping cart. It the user does not have any items in his shopping cart, you can pass null. Passing null will nullify the user's shopping cart on Nosto's end. You must also pass in the shopping cart content in it's entirety as partial content are not supported.

    It is not recommended to pass the current cart contents to an action but instead use the the session

    You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • cart: undefined | Cart

    Returns Action



  • You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • categories: string[]

    Returns Action



  • You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • categoryIds: string[]

    Returns Action

  • Sets the information about the currently logged in customer. If the current customer is not provided, you will not be able to leverage features such as triggered emails. While it is recommended to always provide the details of the currently logged in customer, it may be omitted if there are concerns about privacy or compliance.

    It is not recommended to pass the current customer details to an action but instead use the the session

    You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • customer: undefined | PushedCustomer

      the details of the currently logged in customer

    Returns Action



  • You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • customFields: Record<string, string[]>

    Returns Action

  • Sets the identifier of the current page type to the current request. The different page types are product, front, search, cart, order, category, notfound and other.

    You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    It is not recommended to pass the page type to an action but instead use the the session.

    You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    Returns Action



  • You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • parentCategoryIds: string[]

    Returns Action



  • You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • placements: string[]

    Returns Action

  • Allows you to provide an additional recommender hint that a product is being viewed.

    You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • product: string | Product

      the identifier of the product being viewed

    Returns Action

    the instance of the action

  • Handles click attribution for product recommendations. This can be called when reporting a product view to signal that the view is a result of a click on a recommendation.

    Parameters

    • productId: string

      currently viewed product's product id

    • reference: string

      value of result_id from the recommendation response that was clicked

    Returns Action

  • Sets the restore link for the current session. Restore links can be leveraged in email campaigns. Restore links allow the the user to restore the cart contents in a single click.

    Read more about to leverage the restore cart link

    It is not recommended to pass the restore link to an action but instead use the the session.

    You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • restoreLink: string

      the secure URL to restore the user's current session

    Returns Action



  • You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • searchTerms: string[]

    Returns Action

  • Sets the current variation identifier for the session. A variation identifier identifies the current currency (or the current customer group). If your site uses multi-currency, you must provide the ISO code current currency being viewed.

    It is not recommended to pass the variation identifier to an action but instead use the the session.

    You must invoke [the load method]Action#load on the resultant action in order for the request to be made.

    Parameters

    • variation: undefined | string

      the case-sensitive identifier of the current variation

    Returns Action