I'm sorry we can't provide a better out of the box solution. When Adobe Launch is released, we'll have more options for environments (There will be more than just Staging and Production). Perhaps we may have a better out of the box solution to fit your needs at that point.
We already following the said custom approach but want to go away with that as it will work only if DTM team is centralised. Also, those changes needs to be done on every property and that may mean its prone to human error and misses.
Anyway, It seems like there is no OOTB way to exclude lower environments to get PROD DTM scripts without customization. We will try to customize the DTM component /libs/cq/dtm/components/dynamictagmanagement to fix our problem.
It definitely looks like you're referring to the integration with AEM. Parit's answer contains a link that might answer your question. If not, we can move this thread over to the AEM community where others using this integration might have some additional info.
I am referring to the recommended integration using /etc/cloudservices/dynamictagmanagement/<DTMconfig> and then using cloud config tab on page properties.
When i looked into implementation code of these integrations, it is checking only if 'author' or 'wcmmode=disabled' but dont have any options to verify/configure the lower environments so that staging header will go into these environments.
Below is the snippet from /libs/cq/dtm/components/dynamictagmanagement/dtm_include.jsp
//We use production scripts if we run on a publish instance or the user asked to use these scripts on author instance as well. String dtmScriptsTypeToUse = (mode == WCMMode.DISABLED || authorProdInclude) ? "production" : "staging";
Can you let me know if there is any OOTB way to get staging header code into lower environments?
As far as DTM, the Staging embed code should be used for DEV/Staging/UAT and the Production embed code should be used for PROD. The header code is the only thing that changes, the footer code is the same regardless of which environment you're using.
When you say you set up the integration, are you referring to the AEM integration or which integration are you referring to?