Integrate Google Tag Manager with Google Analytics

:bookmark: This guide will help you set up Google Tag Manager and use it with Google Analytics on your Discourse site. Additionally, it covers configuring variables, triggers, and tags in Google Tag Manager to track page views.

:information_source: This guide covers setting up Google Tag Manager. If you only want to enable Google Analytics for your site, set the G-Tag in the ga universal tracking code site setting. Our settings may still refer to all analytics as universal, but this is a legacy field naming artifact. The following instructions use, and work for, Google Tags.

:person_raising_hand: Required user level: Administrator

Integrating Google Tag Manager (GTM) with Google Analytics (GA) allows you to manage and track events on your Discourse site effectively. This guide covers the full setup process, from creating a GA account to configuring GTM with the necessary tags and triggers.

Summary

  1. Create a Google Analytics account and property.
  2. Set up Google Tag Manager.
  3. Configure GTM variables, triggers, and tags.
  4. Integrate GTM with your Discourse site.

Create a Google Analytics account

  1. Visit Google Analytics and sign in with your Google account.

  2. If you don’t have an account yet, follow the guided steps to create one.

  3. Create a property by clicking on “Admin” and then “Create Property”.

  4. Fill in the required details on the “Property creation” screen.

  5. Enter your business details on the next screen.

  6. Select your business objectives appropriately.

:information_source: Info: Selecting the four sections will most closely match the reports Analytics has typically provided:

7. Choose “Web” as the platform for data collection.

  1. Set up a data stream by entering your site’s URL and a stream name.

:information_source: After successfully creating your web stream, make a note of your Measurement ID. You’ll need this for GTM setup.

Set up Google Tag Manager

  1. Visit Google Tag Manager and create an account.
  2. Set up a container by following the guided steps, and choose “Web” as the platform.

Configure GTM

Variables

  1. Go to the “Variables” tab in GTM and click “New” in the User-Defined Variables section.
  2. Create two Data Layer Variables:
  • Title: DL-page-title
    Type: Data Layer Variable
    Data Layer Variable Name: page.title
    Data Layer Version: 2

  • Title: DL-page-url
    Type: Data Layer Variable
    Data Layer Variable Name: page.url
    Data Layer Version: 2

As an example, choose the variable type:

Then configure the variables, as in this example:

Triggers

  1. Go to the “Triggers” tab and click “New”.

  2. Choose “Custom Event” as the type.

  3. Name the trigger virtualPageView and Save it.

    The end result should look like this:

Tags

  1. Go to the “Tags” tab and create a new tag.

  2. Choose Google Analytics: Google Tag as the tag type.

  3. Configure the tag with the following details:

  • Measurement ID: Enter your Measurement ID from GA.
  • Required Fields to Set:
    • title: {{DL-page-title}}
    • page: {{DL-page-url}}
    • send_page_view: true
    • page_path: {{Page Path}}

When finished it should look like this (note that you can add a userID parameter in addition to the parameters above, but you will need to add an additional variable like DL-page-url.):

  1. Choose the virtualPageView trigger for this tag.
  2. Name your tag and Save it.

Publish your GTM workspace

Publish your container in GTM by clicking the blue “Submit” button in the upper-right corner of the page.

:warning: Important: If you encounter 404 errors from googletagmanager.com, ensure your GTM container changes have been published.

Integrate GTM with Discourse

  1. Go to your Discourse Admin settings and search for gtm container id.
  2. Enter your GTM Container ID (format: GTM-XXXXXX) in the corresponding field.

:warning: Note: Remove any existing Analytics tracking code from the ga universal tracking code setting in Discourse when using GTM, to avoid duplicate tracking.

Reload your site and check the Real-Time content view in GA to confirm that data is flowing through GTM.

Additional Uses

With GTM, you can add more tags to track additional events such as:

Related Links

Last edited by @MarkDoerr 2026-05-12T01:58:41Z

Check documentPerform check on document:
47개의 좋아요

앞서 언급했듯이 GA4 구성 태그가 제거되었으며, 이제 Google 태그를 선택하게 됩니다. 설정 단계는 동일하지만 문서는 업데이트했습니다.

이전에 GA4 태그를 설정했던 사용자의 경우, 자동으로 업데이트되었으므로 사용자 측에서 변경할 필요가 없습니다.

참고로, 현재 GA4/GTM 모범 사례 측면에서 이 설정은 최적의 구성이 아니며, 트리거 섹션의 2단계도 오류가 있는 것으로 보입니다.

페이지 뷰(Page View) 트리거 대신, 이름이 virtualPageView인 사용자 정의 이벤트(Custom Event) 트리거를 사용해야 합니다.

cookieDomain = auto는 Universal Analytics에서 유래한 것으로, 더 이상 필요하지 않습니다. GA4는 서브도메인 내 탐색을 자동으로 처리합니다.

또 다른 모범 사례는 Google 태그를 초기화(Initialization) 시점에 발화하도록 하고, send_page_viewfalse로 설정한 뒤, page_view를 위한 별도의 GA4 이벤트 태그를 사용하는 것입니다.

우리가 구현할 당시에는 사이트 전체 URL + 가상 페이지 경로를 포함하도록 page_location에 오버라이드를 추가했습니다. 이를 통해 표준 GA4 리포트가 올바르게 채워집니다.

1개의 좋아요

스테판 씨,

메모 작성해 주셔서 감사합니다.

이미 일치하는 스크린샷이 있어 트리거 섹션의 2단계를 업데이트했으며, 나머지 부분도 최대한 빨리 업데이트하겠습니다.

2개의 좋아요

설명:

Discourse 포럼에서 Google Tag Manager(GTM) 관련 문제를 겪고 있습니다. 설정 내용과 문제를 자세히 설명드리겠습니다:

  1. GTM 설정:

• Google Tag Manager 컨테이너(ID: GTM-…MZV)를 설정했습니다.

• 테스트 목적으로 GTM에 Google Analytics 4 태그를 추가했으며, 초기화 시 모든 페이지에서 트리거되도록 구성했습니다.

• 복잡한 트리거, 사용자 계층(user layer) 또는 데이터 계층(data layer)은 추가하지 않았습니다. GTM이 정상 작동하는지 확인하기 위한 기본적인 설정입니다.

  1. Discourse와의 GTM 통합:

• Discourse 포럼에서 관리자 설정에 컨테이너 ID(GTM-W…MZV)를 입력하여 GTM을 구성했습니다.

• 웹사이트를 검사해 보니 다음과 같은 상태입니다:

• GTM 스크립트(https://www.googletagmanager.com/gtm.js?id=GTM-W...MZV)가 섹션에 로드되고 있습니다.

• GTM 또는 gtm.js와 관련된 브라우저 콘솔이나 네트워크 탭에 오류가 없습니다.

  1. 문제점:

• GTM 컨테이너를 게시한 후 Google Tag Manager의 **미리보기 모드(Preview Mode)**로 이동하여 웹사이트 URL(https://forum.hobiguru.com)을 입력했습니다.

• 그러나 GTM 미리보기 디버거가 제 사이트에서 GTM 태그가 발견되지 않았다고 표시합니다.

• gtm.js가 로드되고 눈에 띄는 오류가 없음에도 불구하고, 디버거가 GTM 설정을 인식하지 못하고 있습니다.

스크린샷:

• 스크린샷 1: Google Tag Manager의 GTM 컨테이너 설정(GA4 태그 및 트리거 표시).

• 스크린샷 2: GTM 컨테이너 ID(GTM-W…MZV)가 구성된 Discourse 관리자 설정 페이지.

• 스크린샷 3: gtm.js 라이브러리가 제 웹사이트에 성공적으로 로드되었음을 보여주는 브라우저 개발자 도구.

• 스크린샷 4: 오류 메시지 **“No GTM tag found on your website”(웹사이트에서 GTM 태그를 찾을 수 없음)**을 보여주는 GTM 미리보기 모드.



지금까지 시도해 본 것:

네트워크 탭에서 gtm.js가 로드되고 있음을 확인했습니다.

• Content Security Policy(CSP)나 기타 JavaScript 오류가 있는지 브라우저 콘솔을 확인했습니다.

• 캐싱 문제가 없도록 사이트와 브라우저의 캐시를 삭제했습니다.

• 업데이트가 적용되었는지 확인하기 위해 GTM 컨테이너를 다시 게시했습니다.

요청 사항:

gtm.js 스크립트가 정상적으로 로드되고 있음에도 GTM 미리보기 모드가 제 GTM 설정을 감지하지 못하는 이유를 이해할 수 있도록 도움을 주실 수 있나요? 설정이나 통합 과정에서 놓치고 있는 부분이 있을까요?