Setup Guides

Setting Up Google Tag Manager and Your First Tag

We show you how to set up a Google Tag Manager container and create your first GA4 tag, how triggers and variables work, how to send events with the data layer and how to publish safely.

Aurora YazılımEditorial team 6 min read
Setting Up Google Tag Manager and Your First Tag
How do you set up Google Tag Manager?

For Google Tag Manager setup, you create an account and a web container at tagmanager.google.com and add the two code snippets provided to the head and body sections of your site. Then, in the panel, you create your first tag (for example the Google tag for GA4), attach it to a trigger, test it in Preview mode and publish it with the Submit button.

What Is GTM and What Is It For?

Google Tag Manager (GTM) is a free tag management system that lets you manage the analytics, advertising and measurement codes on your site from a single panel. The container code is added to the site just once; other codes such as GA4, Google Ads and the Meta Pixel run from inside that container.

Its biggest benefit is not depending on a developer and a code release for every new measurement need. The marketing team prepares a new conversion tag in the panel, tests it in preview and publishes it. Because every publish is stored as a version, a faulty change can be rolled back with one click.

GTM also comes with a responsibility: anyone with access to the container can add code to the site. That is why you need to hand out permissions carefully and clean up unnecessary tags regularly.

Tags, Triggers and Variables

Three core concepts are the key to understanding GTM. Every setup is made of these three pieces linked together.

ConceptWhat is it for?Example
TagThe code to runGA4 event, Google Ads conversion, Meta Pixel
TriggerWhen the tag should fireAll pages, form submission, a specific click
VariableInformation carried to the tag and triggerPage URL, clicked link, order amount

What is the data layer?

The data layer is a shared JavaScript array through which your site passes information to GTM. You write data that is not visible on the page, such as an order number, product information or form name, into it; GTM reads this data as variables and passes it to tags. That way, measurement rests on a solid base that does not break when the page design changes.

Creating an Account and Container

Go to tagmanager.google.com with the business's Google account. The account and container should be created in the business's name, with an agency given user access only; when the collaboration ends, your measurement infrastructure stays with you.

  1. Press the Create account button, enter your business name as the account name and choose your country.
  2. Enter your site's address as the container name and choose Web as the target platform.
  3. Accept the terms of service; the installation codes appear on the screen.
  4. Note the container ID that starts with GTM-.

Adding the Container Code to Your Site

GTM gives you two code snippets. The first must sit in the head section of every page, as high as possible. The second is a fallback for browsers with JavaScript turned off and is added immediately after the opening body tag. If you use a shared template or header file, adding the code in just one place covers all pages.

htmlin the head section
<!-- 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 -->
htmlright after the opening body tag
<!-- 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) -->

Adding it from the platform admin panel

Many ready-made systems offer a separate field for the container ID and place the code in the right spots themselves. In Aurora's e-commerce infrastructure, the Google Tag Manager code is added from the panel, and a live check screen shows whether the code is actually running.

Your First Tag: The GA4 Google Tag

Once the container is loaded, the first job is usually to start GA4 measurement through GTM. If you do not have a GA4 property yet, first get the measurement ID by following the Google Analytics 4 setup steps.

The Google tag collects page views and enhanced measurement events. For additional events, you create separate GA4 Event tags, enter the measurement ID and the event name, and attach them to the right trigger. The same logic applies to Google Ads conversions: you simply create a Google Ads Conversion Tracking tag with the conversion ID and label from the Google Ads panel and attach it to the thank-you page or the purchase event. Keeping a consistent order of tool, type and purpose in tag names makes it easy to find what you need as the container grows.

  1. From the Tags menu, press the New button and give the tag a clear name (for example GA4 - Google Tag).
  2. In the tag configuration, choose the Google Tag type and enter your measurement ID that starts with G-.
  3. In the Triggering section, choose the Initialization - All Pages trigger so the tag loads before other tags.
  4. Save. The tag is not live yet; preview and publishing come next.

Sending Events with the Data Layer

Having the site write an event to the data layer at key moments, such as a form submission or a purchase, is the most reliable measurement method. Triggers based on visible elements such as clicks or page URLs can break silently when the design changes.

In the example below, when the form is submitted successfully, an event named form_gonderildi is written. In GTM, you create a trigger of the Custom Event type with the event name form_gonderildi and attach the GA4 Event tag to it. To read the form name, you define a variable named form_adi of the Data Layer Variable type.

javascript
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  event: 'form_gonderildi',
  form_adi: 'teklif_formu'
});

In single-page applications (SPA)

In single-page applications written with React or Vue, page transitions do not reload the browser. In this case you can use the History Change trigger, or have the router write an event to the data layer every time the page changes. We cover project setup in our React setup with Vite guide.

Preview, Testing and Publishing

Never publish a change without testing it. The Preview button at the top right opens Tag Assistant; when you enter your site's address, the site opens in debug mode and you can see, page by page or event by event, which tags fire and which do not.

If you are happy with the test, press the Submit button and give the version a descriptive name and a short note. Writing what changed in the version name makes it easier, months later, to find which change caused a measurement problem.

  • Also verify on the GA4 side that events arrive, using the DebugView screen.
  • If something goes wrong, you can republish the previous version from the Versions menu.
  • In larger teams, open separate workspaces to keep changes from getting mixed up.

Common Mistakes and Best Practices

Over time, unused tags pile up in the container, and each one adds to page load. Reviewing the container every three months and pausing unused tags reduces both measurement clutter and the load on page speed; this is also a regular part of our speed and performance management work.

Advertising and measurement tags should not run without visitor consent. GTM's consent settings and the Consent Mode configuration manage this flow. This post gives general information; for your cookie consent setup, check current legislation and consult your legal advisor.

ProblemFix
Data is counted twiceGA4 is loaded both with gtag.js and with GTM; remove one.
Preview cannot connect to the siteAn ad blocker or browser settings; try a window without extensions.
The tag works in preview but not liveThe changes were not published; complete the Submit step.
The click trigger does not workThe required built-in click variables are not enabled; turn them on from the Variables menu.

Frequently Asked Questions

01Does GTM slow down the site?

The container code loads asynchronously, so by itself it does not cause noticeable slowness. The real load comes from the number and weight of the tags added inside the container, which is why removing unnecessary tags matters.

02Can I install the Meta Pixel with GTM?

Yes. You can add the pixel base code with a Custom HTML tag or one of the community templates and attach events to data layer triggers. The details are in our Meta Pixel setup guide.

03What is server-side GTM?

A server-side container first sends measurement requests to a server you manage, then forwards them to analytics and advertising platforms. It gives you more control over data but requires hosting costs and technical maintenance; for most small sites a web container is enough.

A properly set up Tag Manager lets you manage advertising and analytics measurement without depending on code releases, in a testable and reversible way. To set up conversion tracking end to end and run campaigns on this data, explore our digital marketing service, and for reporting and interpretation our SEO and analytics solutions. You can also contact us for a landing page design with measurement codes planned from the start.