Expand my Community achievements bar.

SOLVED

Test Google Tag Manager Script in AEM

Avatar

Level 4

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-a...

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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.

Harwindersingh_0-1727971274923.png

 

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

@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.

Harwindersingh_0-1727971274923.png

 

Avatar

Community Advisor

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:

EstebanBustamante_0-1727981071500.png

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