Server-side GTM With Yandex Cloud
Explore implementing server-side Google Tag Manager using Yandex Cloud, using Hardal for improved performance, better data accuracy, and enhanced user privacy.
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.
- Server-side GTM Container, obviously.
- 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.
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.
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.
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='<HTTPS preview server URL>'
variable for the registry deployment.
Until next time.