> ## Documentation Index
> Fetch the complete documentation index at: https://docs.topsort.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Tag Manager (GTM)

> How to integrate Topsort with Google Tag Manager (GTM) using our banners.js script

export const IntegrationsCard1A = () => {
  return <>
      <style>{`
        .integrations-card-1a {
          display: flex;
          flex-direction: column;
          background-color: #f0f2f4;
          border: 1px solid rgba(0, 0, 0, 0.08);
          border-radius: 12px;
          padding: 1.25rem 1.5rem;
          gap: 0.25rem;
          color: #25253b;
          box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
          transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
          margin-top: 2rem;
        }

        .integrations-card-1a:hover {
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
          border-color: rgba(0, 0, 0, 0.12);
        }

        .dark .integrations-card-1a {
          background-color: #25253b;
          color: #f6f8fa;
          border-color: rgba(255, 255, 255, 0.08);
          box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        }

        .dark .integrations-card-1a:hover {
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
          border-color: rgba(255, 255, 255, 0.12);
        }

        .integrations-card-1a-avatar-row {
          display: flex;
          margin-left: 14px;
          flex-wrap: nowrap;
        }

        .integrations-card-1a-avatar {
          width: 44px;
          height: 44px;
          border-radius: 50%;
          border: 2px solid #f0f2f4;
          margin-left: -14px;
          object-fit: cover;
          box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
          pointer-events: none;
          cursor: default;
        }

        .dark .integrations-card-1a-avatar {
          border-color: #25253b;
          box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
        }

        .integrations-card-1a h2 {
          margin: 0;
          line-height: 1.25;
          font-size: clamp(1.25rem, calc(0.875rem + 1.25vw), 1.75rem);
          font-weight: 700;
          letter-spacing: -0.025em;
          color: #111827;
        }

        .dark .integrations-card-1a h2 {
          color: #f9fafb;
        }

        .integrations-card-1a-subtitle {
          font-size: 0.9375rem;
          font-weight: 500;
          line-height: 1.5;
          color: #4b5563;
          margin: 0;
        }

        .dark .integrations-card-1a-subtitle {
          color: #d1d5db;
        }

        .integrations-card-1a p {
          margin: 0;
          line-height: 1.5;
          font-size: 0.875rem;
          color: #374151;
        }

        .dark .integrations-card-1a p {
          color: #d1d5db;
        }

        .integrations-card-1a a {
          color: #0500ff;
          text-decoration: none;
          font-weight: 500;
          transition: color 0.15s ease;
        }

        .integrations-card-1a a:hover {
          color: #0400cc;
        }

        .dark .integrations-card-1a a {
          color: #8280ff;
        }

        .dark .integrations-card-1a a:hover {
          color: #a19fff;
        }

        @media (max-width: 640px) {
          .integrations-card-1a-avatar {
            width: 38px;
            height: 38px;
            margin-left: -12px;
          }

          .integrations-card-1a-avatar-row {
            margin-left: 12px;
          }
        }

        @media (min-width: 1280px) {
          .integrations-card-1a p {
            font-size: 0.6875rem;
            line-height: 1.4;
            letter-spacing: -0.01em;
          }

          .integrations-card-1a h2 {
            font-size: clamp(1rem, calc(0.75rem + 1vw), 1.25rem);
          }

          .integrations-card-1a-subtitle {
            font-size: 0.75rem;
          }
        }
      `}</style>
      <div className="integrations-card-1a">
        <div className="integrations-card-1a-avatar-row">
          <img src="/images/integration-team/agustin.webp" alt="Agustin - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/amelia.webp" alt="Amelia - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/bernardita.webp" alt="Bernardita - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/borumy.webp" alt="Borumy - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/felipe.webp" alt="Felipe - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/gui.webp" alt="Gui - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/javiera.webp" alt="Javiera - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/linn.webp" alt="Linn - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/marcio.webp" alt="Marcio - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/mateus.webp" alt="Mateus - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/max.webp" alt="Max - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
          <img src="/images/integration-team/rodrigo.webp" alt="Rodrigo - Integrations Team Member" loading="lazy" className="integrations-card-1a-avatar" />
        </div>

        <h2>Need help with your Topsort integration?</h2>

        <p className="integrations-card-1a-subtitle">
          Talk to us, the integrations engineering team.
        </p>

        <p>
          Reach us via <strong>your dedicated messaging channel</strong> or at{" "}
          <a href="mailto:support@topsort.com">support@topsort.com</a>.
        </p>

        <p>
          If you're not a customer yet,{" "}
          <a href="https://www.topsort.com/book-a-demo">book a demo</a> with our
          sales team instead.
        </p>
      </div>
    </>;
};

You can use Google Tag Manager to inject our banner ads script in your platform. Check the Banner JS documentation for more details.

## Prerequisites

<Steps>
  <Step title="Access to Google Tag Manager">
    You need to have a Google Tag Manager account and access to the GTM container for the website where you want to add the HTML.
  </Step>

  <Step title="Google Tag Manager installed on your website">
    Copy the code below and paste it onto every page of your website.

    Paste this code as high in the `<head>` of the page as possible (setting your GTM key):

    ```html theme={null}
    <!-- Google Tag Manager -->
    <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','GTM-XXXXXXX');</script>
    <!-- End Google Tag Manager -->
    ```

    Paste this code immediately after the opening `<body>` tag (setting your GTM key):

    ```html theme={null}
    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->
    ```
  </Step>

  <Step title="Create a div with the desired dimension on your site">
    You need to have a `<topsort-banner>` tag in the HTML with the height and width of the slot you want to display.

    ```html theme={null}
    <body>
      <topsort-banner
        width="600"
        height="400"
        id="<your slot id>"
        category-id="<category id>"
      ></topsort-banner>
    </body>
    ```
  </Step>
</Steps>

## On Google Tag Manager

<Steps>
  <Step title="Log in to GTM">
    Open your Google Tag Manager dashboard.
  </Step>

  <Step title="Select a Workspace">
    Click on 'Current Workspace' from the sidebar and then select another one if needed.
  </Step>

  <Step title="Create a New Tag">
    Click on 'Tags' from the sidebar and then 'New'.
  </Step>

  <Step title="Choose Tag Type">
    Select 'Custom HTML Tag' from the list of tag types.
  </Step>

  <Step title="Add Your HTML">
    Enter your custom HTML code into the HTML text box. The code must include your topsort Marketplace API Key. To get a new token go to app.topsort.com → Settings → API Integration.

    ```html theme={null}
    <script>
      // Set API key for auctions and events
      window.TS = {
        token: "your topsort token",
      };
      // Custom behavior can be configured for each site.
      window.TS_BANNERS = {
        // handle the destination link
        getLink: function(banner) {
          switch (banner.type) {
            case "url":
              return banner.id;
            default:
              return `https://example.com/${banner.id}`;
          }
        },
      };
    </script>
    <script>
    (function() {
        var bannersScript = document.createElement('script');
        bannersScript.src = 'https://unpkg.com/@topsort/banners@0.2.0/dist/banners.mjs';
        bannersScript.type = 'module';
        bannersScript.async = true;

        bannersScript.addEventListener('load', function() {
          window.dataLayer.push({
            event: 'topsort-banners-loaded'
          });
        });

        var analyticsScript = document.createElement('script');
        analyticsScript.src = 'https://unpkg.com/@topsort/analytics.js';
        analyticsScript.type = 'module';
        analyticsScript.async = true;

        analyticsScript.addEventListener('load', function() {
          window.dataLayer.push({
            event: 'topsort-analytics-loaded'
          });
        });

        document.head.appendChild(bannersScript);
        document.head.appendChild(analyticsScript);
      })()
    </script>
    ```
  </Step>

  <Step title="Set Triggering">
    Choose a trigger to determine when the HTML should be executed (e.g., Page View, Click, etc.).
  </Step>

  <Step title="Save and Preview">
    Save your tag and use the 'Preview' mode to test the functionality of your HTML on your site.
  </Step>

  <Step title="Verify">
    Check that the site is showing the banners, that the events are being reported correctly and that the opaqueUserId changes when using different browsers.
  </Step>

  <Step title="Publish">
    Once verified, publish the changes to make the HTML live on your website.
  </Step>
</Steps>

<IntegrationsCard1A />
