Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Setup Server-Side GTM with Docker

' and one of which we’ll use RUN_AS_PREVIEW_SERVER=trueThe first one is our tagging server and the other one is the preview sever.Right now we’re setting up the first one, the tagging server, with this option set PREVIEW_SERVER_URL='debug.gtm.yourdomain.com'. This will let the tagging server know to send duplicate events to this preview server’s endpoint so we can see them in our debug view in our Google Tag Manager.Setting up SSL (even for a subdomain in Route 53) isn’t too difficult, especially with tools like Certbot. I.e. so we can access our subdomain via HTTPs.Certbot integrates seamlessly with Nginx to handle SSL/TLS certificates, ensuring that data between your users and the server is encrypted and secure. This is easier than it sounds.Let’s first start with Nginx.Create a gtm config.Add the following config. Make sure you use your own subdomain here.To save it use Control key + the letter ‘O’ → then Enter. Then Control key + the letter ‘X’ to exit.Enable the config.Test the config and restart Nginx.You should see something like below, if it was successful.Install Certbot.Get the certificate. Remember to change to your own domain here.You’ll have to enter your email address here and agree to a few things.Once you’re done you should be able to see a success message in the terminal.Now we’ll run the Docker Image that Google provides us with to create our tagging server.Remember the config string we got from server side GTM? This is where we’ll use it.Remember the second subdomain we set up? This is where we’ll use that one.Run the command below but make sure you set your own values.Just to clarify again what this is doing, this tagging server will be pointing its preview server url to the other server we’ll create after this. The tagging server will send duplicate events to this preview server so we can see them in our debug view. This other preview server that we haven’t created yet has a domain that is called https://debug.gtm.yourdomain.com.If the command worked and the Docker process is running, we can now go ahead and use the/healthz endpoint on this tagging server to check liveness.You can paste this directly in a new browser window. You should receive a 200 OK back if this is working correctly.From here you should be fine to send events via your first endpoint and you would be able to send these events further using GTM. However, the debug view wouldn’t work, i.e. the debug server that is pointing to this other endpoint.So, we’ll have to configure the second VM instance we’ve set up now.Now you need to go through this entire process for the second VM (instance-2). I.e. install Docker, Ngnix and Certbot and then install another Docker image.The only difference is that we now have a different subdomain.So, your Nginx server block configuration and your Certbot certificate will now use this domain rather than the gtm.yourdomain.com.The Docker image we will run will also differ as I’ve mentioned before as we’re now setting up a preview server rather than a tagging server.See the command below. Make sure to set your own GTM config string.We use the same GTM container config string to connect the two servers.You can go ahead and open up a new window, SSH into your instance-2 and try it out on your own.After you’ve gone through this entire process again for instance-2 and run the Docker image, you can close down the windows, they’ll keep running.Now we have the last part of this. This is where we connect the GA4 events to be transferred via the subdomain to the tagging server we’ve set up.Navigate to your client side Google Tag Manager (GTM) and add another Google Tag under Tags. Here you need to set 3 things.See what this finished tag should look like below. This tag should exist in your client side GTM.You can save and submit your new changes.Now we should first check that our events are sent with a 200 response. Go to Chrome, open up your website and then look in the Network tab.Now search for the gtm.yourdomain.com in the Network tab to see if any events are collected.Be sure to shut off any ad blockers.As you see here there are no errors and we get a status of 200 which means it works fine.If the events are sent this means that the tagging server works, however we still want to test if we’ve managed to set up the preview server as well.Go to your server side GTM container and then open up Preview.A GA4 client should already be set up for you so we don’t have to do anything there. This means that the server will be listening for the GA4 events we’re sending via our client GTM via our tagging server.Once you’ve opened up your debug view with your server container you can reload the website that is collecting the GA4 events and click around.You should now see the events in your server side GTM debug view.Now from here you can decide which events you want to process and where to send them to. If you are familiar with client side GTM, it works about the same.As a side note, it’s not essentially to have this preview server up, the events will be sent regardless but it’s easier to work with.No. You’ll hit limits with the VM instance we did set up here with the micro type. However, I’m unsure how far you can push it by simply setting the machine type to medium. It’s worth a try.That’s up to you. The setup will be the same as if you set up your server automatically with App Engine so you can send your events wherever you’d like, i.e. GA4, BigQuery or the Facebook Conversion API using the built in functionality in ssGTM.If you want to go further with this, you could potentially also open up the contents of the Docker image, and even try to modify it. However, I haven’t tried this myself and it would also be problematic if you would need to update the Docker image later. Perhaps you could set a proxy between this server to pick up raw events?Nevertheless, I hope this answered any questions on how hard it is to set up a tagging server manually and if it’s worth it or not.Bit is an open-source toolchain for the development of composable software.With Bit, you can develop any piece of software — a modern web app, a UI component, a backend service or a CLI script — as an independent, reusable and composable unit of software. Share any component across your applications to make it easier to collaborate and faster to build.Join the 100,000+ developers building composable software together.Get started with these tutorials:blog.bitsrc.ioblog.bitsrc.ioblog.bitsrc.ioblog.bitsrc.ioblog.bitsrc.iodevelopers.google.comconsole.cloud.google.comtagmanager.google.com----Bits and Pieceshttps://github.com/ilsilfverskioldIda SilfverskiöldinLevel Up Coding--Robert Maier-SilldorffinBits and Pieces--11Robert Maier-SilldorffinBits and Pieces--6Ida SilfverskiöldinLevel Up Coding--2Anne-Marie PritchardinKudos Engineering--AL Anany--232Benjamin MarieinTowards Data Science--5Prithwish NathinJavaScript in Plain English--2Arthur De KimpeinDeezer I/O--5Matt BentleyinBetter Programming--3HelpStatusWritersBlogCareersPrivacyTermsAboutText to speechTeams



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Setup Server-Side GTM with Docker

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×