Home / Resources / GTM setup guide

Google Tag Manager setup guide: GA4, Google Ads, and click tracking.

Install GTM, add your GA4 and Google Ads tags, then track internal and external link clicks and register the parameters as custom dimensions in GA4.

In this guide.

1. Install GTM on your CMS.

In tagmanager.google.com, create an account and a Web container, then copy your container ID (format GTM-XXXXXXX). GTM needs two snippets on every page:

<!-- In <head>, as high as possible -->
<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>

<!-- Right after the opening <body> -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
PlatformHow to installNotes
WordPressUse a plugin such as GTM4WP or Site Kit, or paste the snippets into your theme header via a child theme or header-injection plugin.Avoid editing parent theme files; updates overwrite them.
ShopifyAdd the head snippet in theme.liquid and the noscript snippet after the opening body tag.Checkout pages are restricted; use Customer Events (pixels) for checkout tracking.
SquarespaceSettings, Advanced, Code Injection: paste the head snippet in Header and the noscript in Footer.Code Injection requires a Business plan or higher.
WebflowSite settings, Custom code: head snippet in Head code, noscript in Footer code, then publish.Requires a paid site plan.
WixMarketing & SEO, Marketing Integrations, Google Tag Manager, and enter the container ID.Requires a premium plan with a connected domain.

Then open GTM Preview mode and load your site to confirm the container connects. Check that GTM is not also loaded by a plugin, or tags will fire twice.

2. Add the GA4 tag.

Find your Measurement ID in GA4 under Admin, Data streams (format G-XXXXXXXXXX).

  1. In GTM, create a Constant variable named Const - GA4 Measurement ID with that ID, so it is defined once.
  2. Go to Tags, New, choose Google Tag, and enter the variable as the Tag ID.
  3. Set the trigger to Initialization - All Pages and save.
Consent: if you serve visitors in regions with consent requirements, configure Consent Mode and a consent banner before publishing. Do not skip this step.

3. Add Google Ads tags.

  1. Conversion Linker: new tag, type Conversion Linker, trigger All Pages. It preserves click IDs (GCLID) for accurate attribution.
  2. Google Ads conversion: in Google Ads, create a conversion action and copy the Conversion ID and Label. In GTM, add a Google Ads Conversion Tracking tag with those values.
  3. Trigger it on the real success event, such as a thank-you page view or a form-success event, not a button click.
  4. Optional: add a Google Ads Remarketing tag on All Pages if you run remarketing.

Alternatively, import GA4 key events into Google Ads to avoid duplicate conversion actions. Use one method per conversion, not both.

4. Track internal and external clicks.

This sends each link click to GA4 with three parameters: the page it happened on, the link text, and the link URL.

Variables

Under Variables, Configure built-in variables, enable Click Text, Click URL, Page Path, and Page Hostname. Click Text often returns nothing for image links; also enable Click Classes or Click ID if needed.

Triggers

Create two Just Links triggers (select Some Link Clicks, and leave Wait for Tags on):

TriggerFires when
Click - InternalClick URL contains kp-analytics.com (use your own domain)
Click - ExternalClick URL does not contain your domain

GA4 event tags

Create two Google Analytics: GA4 Event tags using your Measurement ID variable:

TagEvent nameTrigger
GA4 - Click Internalclick_internalClick - Internal
GA4 - Click Externalclick_externalClick - External

Add these event parameters to both tags:

Parameter nameValue
click_text{{Click Text}}
click_url{{Click URL}}
click_page_path{{Page Path}}
Avoid double counting: GA4 Enhanced Measurement already records outbound clicks as a click event. If you track external links here, turn off Outbound clicks under Data streams, Enhanced measurement, gear icon. Also, GA4 already attaches page_location to every event, so click_page_path is a cleaner path-only value for reporting.
Privacy: mailto: links and URLs with query strings can contain personal data. Exclude those links from the triggers, or strip the query string with a custom JavaScript variable before sending.

5. Register GA4 custom definitions.

GA4 only shows custom parameters in standard reports and Explorations once you register them as custom dimensions.

  1. In GA4, open Admin, Data display, Custom definitions.
  2. Click Create custom dimension.
  3. Create one dimension per parameter, with scope Event:
Dimension nameScopeEvent parameter
Click TextEventclick_text
Click URLEventclick_url
Click Page PathEventclick_page_path

The event parameter must match the GTM parameter name exactly, including case. Standard properties allow 50 event-scoped custom dimensions, so keep names deliberate. Data appears only from the time of registration, and reports can take 24 to 48 hours to populate. Registering does not backfill earlier events.

Optionally, mark click_external as a key event under Admin, Data display, Events if outbound clicks are a goal for you.

6. Test and publish.

  1. Open GTM Preview, load your site, and click an internal and an external link. Confirm the matching tag fires once per click.
  2. Open GA4 Admin, DebugView and check that click_internal and click_external arrive with all three parameters populated.
  3. Back in GTM, click Submit, add a version name and description, and publish.
  4. After 24 to 48 hours, build an Exploration with Event name and your three custom dimensions to see the data.

Once click data is flowing, report on it in the free GA4 report template.

GTM setup FAQ.

Where do I put the Google Tag Manager code?

Place the first snippet as high as possible in the head of every page and the noscript snippet immediately after the opening body tag. Most CMS platforms offer a plugin or settings field so you do not edit theme files.

Why are my custom dimensions empty in GA4 reports?

Custom dimensions only collect data after they are created, and reports can take 24 to 48 hours to populate. Events sent before registration are not backfilled.

Will custom click tracking double count GA4 outbound clicks?

It can. GA4 Enhanced Measurement already records outbound clicks. Turn off outbound clicks in Enhanced Measurement if you track external links with your own tag.

Is it safe to send click URLs to GA4?

Avoid sending personal data. Links such as mailto addresses or URLs with query strings can contain personal information, so strip or exclude them before sending.

Related services.

Want this built and validated for you? See GA4 & GTM setup, website conversion tracking, or an analytics audit of your current container.

Want GTM set up right the first time?

Start a conversation ↗