Server-Side Google Tag Manager (SGTM)
Create sGTM Container on GTM
- Go to your Google Tag Manager account.
- Navigate to
Admin
and click the plus icon on the right.
- Choose server.
- Go to
Clients
and clickNew
.
- Set up your client tag.
This will connect your sGTM container with your current client GTM. So, please make you sure add your current GTM ID, like GTM-XXXXX
- Go to
Admin
and clickContainer Settings
.
- Visit the Hardal dashboard and copy the
Hardal sGTM Container URL
.
- Paste your
Hardal sGTM Container URL
.
Testing your sGTM Container
You can check if your sGTM container is working correctly in two ways.
- Copy and paste your Hardal sGTM Container URL into your browser and add
/healthy
to the end of your URL. You should see justOK
in your browser.
Another way to check your container is the debug view.
- Go to your server-side container workspace and click preview by choosing your current server-side container URL.
- In your Preview screen, click the three-dots icon, then copy your manually sending request cURL code to the terminal and run it.
- You should see your test request in your preview sGTM.
Update the script source domain
By default, Tag Manager or the Google tag (gtag.js) loads their dependencies from Google-owned servers, such as www.googletagmanager.com (opens in a new tab). You need to update the script URL on your website to load dependencies through Hardal Server.
To load the GTM code via your server container:
-
- Locate the existing Tag Manager code on the page.
-
- Replace the string www.googletagmanager.com (opens in a new tab) with the domain name of your tagging server in the
<head>
and<body>
of the Google Tag Manager installation code
- Replace the string www.googletagmanager.com (opens in a new tab) with the domain name of your tagging server in the
-
Head
<!-- 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=
'<YOUR_HARDAL_CONTAINER_URL>/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->
- Body
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://<YOUR_HARDAL_CONTAINER_URL>/ns.html?id=TAG_ID"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
Congratulations 🎊 Your server-side GTM is ready to use.