nosto_element
. The identifier of the element denotes the placement identifier. An example placement is as follows:setPlacements
which expects an array of strings. In order to support dynamic placements setup in the Nosto backend, we recommend that instead of setting the placements array contents directly from your application, you use the following API to get a list of placements for the page:api.placements.getPlacements()
returned an array with 2 placements: ['frontpage-center-1', 'frontpage-banner']
and then let's assume that we would have setup in the backend a recommendation campaign for frontpage-center-1
and a content campaign for frontpage-banner
. api.placements.injectCampaigns()
. The function expects an object where the field keys are the placements to be injected and values are either a string or an object with a string field named html
. The function will scan the document to find the active placements and insert the html to the right location. Any javascript blocks within the html content will be executed as well.campaign
field and will instead contain a recommendations
field which has the HTML content of all campaigns, regardless if they are content or recommendation campaigns. You can then pass that field to a utility method api.placements.injectCampaigns
that will inject the HTML into the page.injectCampaigns
method automatically handles the injection of both the recommendations and the content. If there is no response for a specified placement, the element (into which to be injected), remains as-is.