Dynamic Blocks in Magento are not stored in the page cache and are rendered after the page loads. Klevu’s Javascript can power up before dynamic blocks have loaded. In order to use recommendations within Magento Dynamic Blocks you can change the code provided for recommendations in KMC to trigger powerUp for the block.
Recommendations code provided in KMC
<div class="klevu-recs" id="k-klevu-recs-id-replace-me-1234567890ab"></div>
Adapted code for Recommendations in Dynamic Blocks.
<div class="klevu-recs"
id="k-klevu-recs-id-replace-me-1234567890ab"
data-bind="afterRender: function(recsTargetElement) {
if ('undefined' !== typeof klevu && 'undefined' === typeof recsTargetElement.recsObject) {
let myRecsbox = klevu.recs.clone({
recId: recsTargetElement.id,
apiKey: klevu.getGlobalSetting('recs.apiKey', klevu.getGlobalSetting('global.apiKey')),
element: recsTargetElement
});
myRecsbox.powerUp();
}
}"></div>