Optional. With no container ID the website carries no Tag Manager code at all: no snippet, no dataLayer. Ask KIMS whether they want analytics before spending time here.
#How the code uses it
#One setting on the site build
| Fact | Value |
|---|---|
| Setting | GTM_ID, a line in the environment's kims-site-env Jenkins secret file. Not a Helm value: the CMS pods never read it |
| Read by | The site build, which passes it to the website build as NEXT_PUBLIC_GTM_ID |
| Format | GTM- followed by 4 to 10 capital letters or digits, for example GTM-AB12CD3 |
| A wrong value | Is treated as "no container": the pages carry no tag, and the build does not fail. Check the output (Check the built site) |
| What is added | Google's standard head snippet, loading https://www.googletagmanager.com/gtm.js?id=<GTM_ID>, with dataLayer set up first |
| What is not added | Google's <noscript> iframe, deliberately: it would load Tag Manager for visitors without JavaScript with no consent check |
| When it changes | Only at the next site build. Changing GTM_ID needs a rebuild of the live version |
GA4 is not configured in the code. If KIMS wants GA4, they add a Google tag (GA4 configuration) inside their Tag Manager container. Consent, tags and triggers are managed in Tag Manager by KIMS's marketing team, not in KIMS v2.
#Get a container ID
#KIMS already has one
Ask KIMS's marketing or web team for the Web container ID used by the old site. It is shown at the top of the container's workspace in Tag Manager, next to the container name, as GTM-XXXXXXX. Use one container for production. For UAT, use either no container (recommended, so test visits do not pollute their analytics) or a separate test container.
#Create a new container
Done by a KIMS person who will own it:
- Open
https://tagmanager.google.com/and sign in with a KIMS Google account. - Click Create Account.
- Account Name:
KIMS Hospitals. Country: India. - Container name: the website host, for example
www.kimshospitals.com. Target platform: Web. - Click Create, read and accept the Google Tag Manager Terms of Service (the KIMS owner does this, not the engineer).
- A dialog shows the install snippet. Close it: KIMS v2 adds the snippet itself.
- Copy the container ID shown at the top of the workspace,
GTM-XXXXXXX. - In Admin > User Management, add a second KIMS administrator so the container is not owned by one person.
Tags inside the container (GA4 and so on) are added in Tag Manager and only take effect after KIMS clicks Submit > Publish there. No KIMS v2 build is needed for that.
#Put the ID in the site build settings
#Edit kims-site-env
The site build reads its settings from the Jenkins secret file credential kims-site-env in the environment's folder (jenkins/credentials). It is a list of NAME=value lines; the example files carry the line commented out:
# Google Tag Manager container, if any:
# GTM_ID=GTM-XXXXXXX- Open your filled-in copy of
site-env-production.example(outside Git). - Replace the commented line with
GTM_ID=GTM-AB12CD3(the real ID, no spaces, no quotes). - In Jenkins, open the folder (
kims-production), Credentials, thekims-site-envcredential, Update, and upload the edited file. Save. - Run
kims-production/kims-site-buildwith Build with Parameters:PUBLISH_VERSIONthe live version (the CMS Builds screen shows it),CAUSErebuild.
For UAT, do the same in the kims-uat folder only if KIMS wants UAT tracked.
#Check the built site
#Look for the snippet in the home page
curl -s https://<SITE_HOST>/ | grep -o "googletagmanager.com/gtm.js?id=[^'\"&]*\|GTM-[A-Z0-9]*" | sort -ucurl -s https://<SITE_HOST>/ | grep -o "googletagmanager.com/gtm.js?id=[^'\"&]*\|GTM-[A-Z0-9]*" | sort -u(Invoke-WebRequest -UseBasicParsing https://<SITE_HOST>/).Content | Select-String -Pattern "GTM-[A-Z0-9]+" -AllMatches | ForEach-Object { $_.Matches.Value } | Sort-Object -UniqueExpected with a container: the container ID, for example GTM-AB12CD3 (on Linux and macOS also the googletagmanager.com/gtm.js?id= text). Expected without one: nothing at all.
#Check in the browser
- Open the website in Chrome, with developer tools (F12) on the Network tab.
- Reload. Filter by
gtm.js.
You should see one request to www.googletagmanager.com/gtm.js?id=GTM-... with status 200. In Tag Manager, Preview mode (Tag Assistant) can then connect to the site.
#If it does not appear
| What you see | Cause | Fix |
|---|---|---|
No GTM- in the page |
GTM_ID missing, commented out, or not matching GTM- plus 4 to 10 capitals and digits (lower case, spaces or a pasted URL count as "no container") |
Fix the line in kims-site-env, rebuild |
The ID is in the page but gtm.js is blocked in the browser console |
A Content Security Policy on the distribution (a CloudFront response headers policy) does not allow Google's hosts | KIMS adds https://www.googletagmanager.com to script-src and connect-src, plus the hosts their tags use (for GA4: https://*.google-analytics.com, https://*.analytics.google.com) |
| Still the old page | The build did not run, or CloudFront served a cached page | Check the build on the CMS Builds screen; the build invalidates CloudFront |
#UAT and production
| UAT | Production | |
|---|---|---|
GTM_ID |
Usually none, or a test container | KIMS's live container |
| Where | kims-uat folder, kims-site-env |
kims-production folder, kims-site-env |
#Sources
kims-v2/apps/website/src/lib/analytics/gtm.tskims-v2/scripts/site-build/run.mjskims-v2/deploy/jenkins/site-env-production.examplekims-v2/deploy/jenkins/site-env-uat.examplekims-v2/deploy/jenkins/README-site.mdkims-v2/docs/CONFIG.md- https://support.google.com/tagmanager/answer/6103696
- https://support.google.com/tagmanager/answer/14842164
- https://developers.google.com/tag-platform/security/guides/csp