Hi ,
Are you using/calling your plugin functions (Code inserted in Appmeasurement Library) from code on the page (or a developer console) or even non-analytics code blocks in DTM (like Third Party Tags) ? . If yes, then it is happening because at this point in time, by default, DTM creates your analytics object (usually an "s", as in "s.pageName") with a local scope. This means it should be able to be referenced from any custom code blocks within DTM that are tied to your analytics tool.
The only way to overcome the above situation is to define your own "s" object within your library. This does mean you can't let DTM manage your library, but the change you need to make is pretty minor. You need a "Custom" configuration, and you'll need to "Set report suites using custom code below" (since you're essentially going to be overwriting the "s" object that DTM created, where it set your report suites for you) and in this way "s" object is created with a Global Scope.
Also, Can you please confirm that when your plugin code is not working then ,Are you seeing any error in the Dev console like : "Uncaught Reference Error : s is not defined".
Thanks & Regards
Parit Mittal