Adding Google Tag Manager to Universal Login

Overview

This article explains how to add Google Tag Manager to the Auth0 Universal Login template using the Auth0 Management API.

Applies To

  • Universal Login

Solution

Follow these steps to add Google Tag Manager to the Auth0 Universal Login template using the Auth0 Management API:

  1. Ensure a custom domain is configured in the Auth0 tenant. See Custom Domains for detailed steps.
  2. Use the Management API to update the template of choice and insert the tag inside the head and body of the Universal Login using the endpoint described in Set template for New Universal Login Experience
    Example request body (content-type: text/html):
<!DOCTYPE html>
<code>
   <html>
      <head>
         <script>(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','YOUR-ID-HERE');
         </script>
         {%- auth0:head -%}
      </head>
      <body>
         {%- auth0:widget -%}
      </body>
   </html>
</code>
  1. After following the steps above, Google Tag Manager should now be embedded into the Universal Login.