Couple of things I would like to know from your before suggesting solution
1. is your application SPA or multi-page?
2. Do you firing rule for pageview on pageload of any page?
3. What event you are firing and you are not getting your datalayer captured in debugger?
There could be separate recommendations for SPA and separate for Multi page application.
Share more information so that we can help you
Answers to your question:
1. Currently it is a test application which is not SPA
2. The script is defined in document.ready