Google Tag Manager

Add the Google Tag Manager Script

Partytown Script

Set the script element’s type attribute to text/partytown. For example:

  <script type="text/partytown" src="https://www.googletagmanager.com/gtag/js?id=YOUR-ID-HERE"></script>
  <script type="text/partytown">
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'YOUR-ID-HERE');
  </script>

Google Analytics 4 (GA4)

GA4 responses come with the correct CORS headers, so you will not have to proxy the requests to www.google-analytics.com. Older versions of Google Analytics required proxying, but have been sunset by Google and are no longer supported.

Forward Events

Google Tag Manager uses the dataLayer array to send events. In order for Partytown to forward the calls to window.dataLayer.push({..}), the forward config should add "dataLayer.push". Please see forwarding events and triggers for more information.

Example Config

{
  "forward": ["dataLayer.push"]
}

Please see the integration docs for framework specific configuration.

Made with ❤️ by

© 2024 Builder.io, Inc.

Introducing Visual Copilot.

100% free. Supports all popular frameworks.

Try Visual Copilot