Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Adding GTM code into the <body> tag of Service Portal Pages

LizB
Tera Expert

I have been told to place the following GTM code into the <head> tag for Google Tracking for our Community:

<!-- Google Tag Manager -->
<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>
<!-- End Google Tag Manager -->

We have already done something like this for previous version of Google Analytics by creating a UI script to insert this code in the header for our Service Portal Community.

However, I am stumped as to how to include the following code in the <body> tag.  I am assuming that this code needs to go on every Service Portal page.  Any ideas?  Do I need to add an HTML widget to every Service Portal page and then include this code?  We have a page for creating knowledge articles that uses the Form widget, so in this case there isn't actually a Service Portal page.  Do I need to update the Form widget to add the code.

Regards,

Liz

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
1 REPLY 1

Erik Stolberg
Tera Guru

Easiest way would be to include it in a widget already included on every page- the header menu widget. Just verify your Community portal is using the default "Header Menu" widget (sp_instance_menu table to verify). If so, add in the body text into the widget body HTML.