Test Google Tag Manager Script in AEM | Community
Skip to main content
NageshRaja
Level 5
October 3, 2024
Solved

Test Google Tag Manager Script in AEM

  • October 3, 2024
  • 2 replies
  • 1246 views

hey guys,

 

I have been given a script for google tag manager and been asked to test it.

I know its supposed to be injected into the <head></head>

 

I was reviewing the prev question on this thread at https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-assets/adding-gtm-on-aem-authoring-environment/td-p/410019

They have the below approaches -

  1. Find a clientlib that's loaded everywhere on each page
  2. Sling Pipeline Transformer that injects your GTM script tag into the <head> tag
  3. Sling Filter that injects this on all HTML requests

 

Is there any other way and what is the expected output when the script is included in the page?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Harwinder-singh

@nageshraja  Once the script is added into the HEAD , it will show up in the source html code as well as in the network tab. you should see something like a gtm.js show up in the network tab.

 

2 replies

Harwinder-singh
Community Advisor
Harwinder-singhCommunity AdvisorAccepted solution
Community Advisor
October 3, 2024

@nageshraja  Once the script is added into the HEAD , it will show up in the source html code as well as in the network tab. you should see something like a gtm.js show up in the network tab.

 

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
October 3, 2024

Hi,

 

The link you are referencing is for AEM Assets, so the methods you listed are uncommon if you are using AEM Sites with an authoring experience. Instead, the most common way to include any script in the <head> is by modifying the page component from which all templates inherit. In the page component, there could be several places where a developer could add the GTM script, in the below screenshot you can see in RED some of those areas:

The expected output is that the script tag appears in the <head> of your HTML. Therefore, if you inspect your page and look at the <head> tag, you should find the GTM script.

Something like this:

<head> <title>Your Page Title</title> <script async src="https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXX"></script> </head>

 

Once the script is in the HTML, there is a call that will happen and can be reviewed in the Network tab as explained by @harwinder-singh 

 

Hope this helps

Esteban Bustamante