Google Tag Manager has a built-in mechanism that automatically replaces the
document.write() function with its own functionality. This behavior cannot be directly prevented or disabled in Google Tag Manager settings.
However, there are a few workarounds you can implement to prevent the overwriting of
- Use custom HTML tags: Instead of using the built-in tags provided by Google Tag Manager, you can create custom HTML tags where you have control over the code. This way, you can avoid the automatic overwriting of document.write().
- Implement code in a custom HTML tag: If you need to include a script that uses document.write(), you can put this script directly into a custom HTML tag in Google Tag Manager. By doing this, the script will not be affected by the automatic replacement.
- Modify the script to avoid using document.write(): If possible, consider modifying the script to use alternative methods instead of document.write(). This will allow you to retain compatibility with Google Tag Manager while avoiding the overwriting issue.
It's important to note that Google Tag Manager's automatic replacement of
document.write() is designed to maintain secure and reliable tag management. By using the recommended workarounds, you can still achieve your desired functionality without compromising the benefits of Google Tag Manager.