Hi Sigurd!
Have you checked the documentation regarding “Integrate with Google Analytics (GA4)” (go to docs). I believe this article can be quite helpful.
I believe this is the simplest way to integrate Google Tag Manager for a single app:
- Add the Head-script under Custom Header Tags in apps (this is the correct place = App Settings → Other → Custom Header Tags) and a coded component in the app you want to track. Important, by using this method you will only track the app in context. If you add the Head-script under the Custom Header Tags in environment settings, you will track all the apps in this environment (Environments → [ANY ENVIRONMENT YOU WANT TO TRACK], and locate section Other → Custom Header Tags).
- In regards to this query: ensure the code is placed “as high in the
<head>
of the page as possible” and “immediately” after the opening<body>
tag" I have the following answer. The code does not have to be the first direct child of the<body>
tag. It is recommended to place it as early as possible. So, a coded component could be placed in the top of your default view. The<script>
tag should be placed in the header, hence it should be uploaded to thescript sources
setting in Environment Config. For more information, please see this community post. Furthermore, the<noscript>
tag is used for browsers not supporting javascript. Appfarm does not work on browsers not supporting javascript. So the<noscript>
part of the setup is probably something you will not need to consider. - In order to track different environments you must add the Custom Header Tags to the different environments you want to track (see point one on where to do this).
I would recommend to test this implementation thoroughly! Other than that I believe you should be able to complete the integration! If you have any other questions or run into a problem, do not hesitate to reply to this post.
Good luck!