To use the api you will need to put the code inside a discourse-plugin block. (It’s still javascript, just with a sprinkling of Discourse added on top).
So something like:
<script type="text/discourse-plugin" version="0.2">
api.decorateCooked($elem => {
refTagger.tag($elem[0]);
});
</script>