Based on a feature available with Oracle Maxymiser - a beneficial functionality they had was the ability to run a function when the targeting for Single Page Application no longer qualifies e.g. when the page URL changes to something not matching the targeting of a campaign.
This was typically used to remove content that was added to the DOM due to the campaign script that wouldn't be removed when the URL/elements change.
Example:
Campaign Script:
  • Inserts a banner at the top of the page, only relevant for this page.
Once the user proceeds to a different page, like https://stable.nationalexpress.com/coach/#/choose-fare, run a rollback function (as targeting no longer suffices) to remove the banner.
Here's what it looked like in Oracle Maxymiser:
spa.when([
spa.conditions.element('app-ticket-item-tickettype > div > .text-right > p'),
]).then(() => {
// If conditions match
// We do our script
}).rollback(() => {
// We revert changes when the conditions no longer match
});