Hi,
The DTM Embed code (Header code) needs to be placed in the 'head' section and the footer code needs to be placed right before the 'body' tag ends.
Thus, it's recommended that the data layer is called and populated before the DTM code is referenced. However, typically data layer implementation is subject to your environment.