Greetings, internet!
Since Server-Side GTM can operate as a simple Docker image, we’ve decided to expand our cloud provider options to include Yandex Cloud, in addition to Azure, GCP, and AWS. Today, I’d like to share how we made this happen!
First, let’s dive into how the Manual Setup works with Server-Side Google Tag Manager. I’ll be using some helper images from the official Google Docs after listing what we need in bullet points.
What we need
Server-side GTM Container, obviously xd (if you don’t have one, make it happen with Hardal for **free)
Custom Domain
Yandex Cloud account
With these ingredients and a bit of Hardal magic, we’re able to deploy our server-side Google Tag Manager on Yandex Cloud.
Structure of Server-side Google Tag Manager
This diagram essentially shows how it works. You’re already familiar with how Web GTM operates, but now it’s time to move it to the server that Hardal provides on Yandex Cloud.
Flowchart
Let’s start with the first step: creating a Serverless Container on Yandex Cloud that runs the Server-Side Google Tag Manager image. To accomplish this, we’ve created a Container Registry for the sGTM image. Now, we’re ready to create our Serverless Container.
Remember, we need Preview Server and Tagging Server
For the preview server, we ran the sGTM registry with the RUN_AS_PREVIEW_SERVER=true variable.
After successfully deploying the Preview Server image, we’re now ready to map a custom URL to the container. While Yandex Cloud doesn’t provide a direct way to manage domains for your containers, there’s no such thing as “impossible.” So, we found a workaround to make it happen.
Solution
The plan was to create an API Gateway and integrate it with the sGTM container. Instead of mapping the custom domain directly to the container, we mapped it to the API Gateway and connected the container to the gateway. After generating a Let’s Encrypt certificate for our custom domain, we were nearly at the final result. It was time to map our domain to the API Gateway.
The tricky part is that you can connect the domain **www.example.com, but not **example.com. This is due to how CNAME records are processed by DNS hosting. To resolve this, we created an ANAME DNS record on Yandex Cloud DNS.
With the configurations provided below, our API Gateway is now ready to use with a custom domain and serverless container. 🎊
/{proxy+}: x-yc-apigateway-any-method: x-yc-apigateway-integration: type: serverless_containers container_id: containerID service_account_id: serviceAccountID
Now we have the sGTM Preview Server with a custom domain working on Yandex Cloud. For the Tagging Server, we follow the same process, but instead of using the RUN_AS_PREVIEW_SERVER=true variable, we need to use the PREVIEW_SERVER_URL=” variable for the registry deployment.
Until next time.
Discover more from Coursity
Subscribe to get the latest posts sent to your email.