Thank you for sharing this. I submitted a PR for the fix (/cc @neil)
https://github.com/discourse/discourse-adplugin/pull/66