How to add custom JS code to the 404 pages?

We just switched our community to Discourse and I am wondering if it is in some way possible to add custom JS code to the 404 pages as we want to track which old URLs are still visited e.g. add a different/dedicated Google Analytics tracker to these pages.

Mini plugin required for this? Or is there a simpler way?

You can add some JS code that detects if the current page is a 404 (many elements there you can use to detect) and after detection it runs whatever you want. Should be doable in a theme-component.


You’re right! That solved it for me. Normal JS is working, just not the ones within text/discourse-plugin tags.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.