Integrando o Google Tag Manager com o 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 and ga tracking code settings in Discourse.

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 @jessii 2024-08-03T01:04:37Z

Check documentPerform check on document:
46 curtidas

Conforme observado, a tag de configuração do GA4 foi removida e agora você escolherá a Tag do Google. As etapas de configuração permanecem as mesmas, mas atualizei a documentação.

Para quem configurou anteriormente a tag do GA4, ela deve ter sido atualizada automaticamente e não requer nenhuma alteração da sua parte.

Vale a pena mencionar que esta não é uma configuração ideal em termos das melhores práticas atuais do GA4/GTM e que a etapa nº 2 na seção “Triggers” parece estar incorreta.

Em vez de um gatilho de “Page View”, este deveria ser um gatilho de “Custom Event” com o nome virtualPageView.

cookieDomain = auto parece ser um resquício do Universal Analytics e não é necessário. O GA4 lida automaticamente com a navegação entre subdomínios.

Outra melhor prática é ter a tag do Google disparada na “Initialization”, com send_page_view definido como false e, em vez disso, ter uma tag de evento GA4 separada para page_view.

Quando implementamos, também adicionamos um “override” para page_location com a URL completa do site + o caminho da página virtual. Isso preencherá corretamente os relatórios padrão do GA4.

1 curtida

Olá Stefan,

Obrigado por estas notas.

Atualizei a etapa nº 2 da seção Gatilhos, pois já tinha capturas de tela correspondentes, e atualizaremos o restante o mais rápido possível.

2 curtidas

Descrição:

Estou enfrentando um problema com o Google Tag Manager (GTM) no meu fórum Discourse. Deixe-me explicar minha configuração e o problema em detalhes:

  1. Configuração do GTM:

    • Configurei um contêiner do Google Tag Manager (ID: GTM-…MZV).
    • Para fins de teste, adicionei uma tag do Google Analytics 4 no GTM, configurada para disparar em todas as páginas durante a inicialização.
    • Não adicionei nenhum gatilho complexo, camada de usuário ou camada de dados. É apenas uma configuração básica para verificar se o GTM está funcionando.
  2. Integração do GTM com o Discourse:

    • No meu fórum Discourse, configurei o GTM inserindo o ID do contêiner (GTM-W…MZV) nas Configurações de Administrador.
    • Ao inspecionar meu site, posso ver que:
  3. O Problema:

    • Após publicar meu contêiner do GTM, fui para o Modo de Visualização no Google Tag Manager e inseri o URL do meu site (https://forum.hobiguru.com).
    • No entanto, o Depurador de Visualização do GTM informa que nenhuma tag GTM foi encontrada no meu site.
    • Apesar do gtm.js estar carregando e não haver erros visíveis, o depurador não está reconhecendo a configuração do GTM.

Capturas de Tela:

  • Captura de Tela 1: Configuração do contêiner GTM no Google Tag Manager (mostrando a tag GA4 e os gatilhos).
  • Captura de Tela 2: Configurações de Administrador do Discourse mostrando o ID do contêiner GTM (GTM-W…MZV) configurado.
  • Captura de Tela 3: Ferramentas de Desenvolvedor do Navegador mostrando que a biblioteca gtm.js está sendo carregada com sucesso no meu site.
  • Captura de Tela 4: Modo de Visualização do GTM mostrando a mensagem de erro: Nenhuma tag GTM encontrada no seu site.



O que Tentei Até Agora:

  • Confirmei que o gtm.js está carregando na aba Rede.
  • Verifiquei o console do navegador em busca de quaisquer erros de Política de Segurança de Conteúdo (CSP) ou outros erros de JavaScript.
  • Limpei o cache do meu site e do navegador para garantir que não haja problemas de cache.
  • Republiquei o contêiner do GTM para garantir que ele esteja atualizado.

Solicitação:

Alguém pode me ajudar a entender por que o Modo de Visualização do GTM não está detectando minha configuração do GTM, mesmo que o script gtm.js esteja carregando corretamente? Há algo que estou perdendo na configuração ou no processo de integração?