Review the extension block and make the call.
<div class="page-width card recently-viewed">
<h3>{{ block.settings.heading }}</h3>
<ul id="recently-viewed-list"></ul>
</div>
<script>
(function () {
var viewed = JSON.parse(localStorage.getItem('viewed') || '[]');
{% if block.settings.product %}
viewed = viewed.filter(function (v) {
return v.url !== {{ block.settings.product.url | json }};
});
viewed.unshift({
title: {{ block.settings.product.title | json }},
url: {{ block.settings.product.url | json }}
});
localStorage.setItem('viewed', JSON.stringify(viewed.slice(0, 8)));
{% endif %}
var list = document.getElementById('recently-viewed-list');
viewed.slice(0, 4).forEach(function (v) {
list.innerHTML += '<li><a href="' + v.url + '">' + v.title + '</a></li>';
});
})();
</script>
{% schema %}
{
"name": "Recently viewed",
"target": "section",
"settings": [
{ "type": "text", "id": "heading", "label": "Heading", "default": "Recently viewed" },
{ "type": "product", "id": "product", "label": "Product" }
]
}
{% endschema %}