Home App Docs Blog Github

Prevent Google Analytics (or other third party scripts) from tracking while in the Builder iframe

You may be seeing traffic from the /apps/builder pages due to viewing content in the editor. Because the tracking scripts are outside of the Builder.io control there is no automatic solution that would solve this issue.

However, we can recommend adding this short script into your page to work around the issue:

if (window.name == 'preview-frame') return;

An example of how this may be used with Google Tag Manager:

<!-- Google Tag Manager -->
<script>
// INSERT THIS AT TOP OF THE SCRIPT TAG
if (window.name == 'preview-frame') return;
// END OF INSERT

// EXISTING CODE SNIPPET
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');
</script>
<!-- End Google Tag Manager -->