Track the last collection by storing or updating a cookie on every collection page visit. If it comes across a continue shopping link then it updates that link to point back to that last collection.
Add the attribute data-continue-shopping-link
to any link you want to act as a continue shopping link.
Requires the current template to be passed to it from liquid: