Site icon Tech Publications

How To Add a Google Tag in a Page?

how to add GTM

Adding a Google Tag to a page allows you to monitor and track the traffic on your website. The following are some reasons why you might want to do this:

  1. Measuring website traffic: Google Analytics provides detailed insights into the number of visitors, page views, and other metrics for your website, allowing you to see how well your site is performing.
  2. Improving website performance: By tracking website traffic, you can identify areas of your site that are underperforming and make changes to improve them.
  3. Targeting advertising: Google Analytics provides data that can be used to target your advertising more effectively, helping you to reach your desired audience and maximize the impact of your advertising campaigns.
  4. Understanding user behavior: Google Analytics allows you to see how users interact with your website, including which pages they visit, how long they stay on your site, and what actions they take. This information can help you optimize your site for a better user experience.
  5. Making informed decisions: The data provided by Google Analytics can be used to make informed decisions about your website and online marketing efforts, allowing you to allocate resources more effectively and maximize your return on investment.

Here is an example of the code you need to add a Google Tag to a webpage for monitoring traffic:

  1. Copy the Google Tag Manager code provided and paste it into the HTML of your website, usually in the header section:
<!-- 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=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->
  1. Add the following code just below the opening <body> tag in your HTML:
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

Note: Replace GTM-XXXXXXX in the code with your own Google Tag Manager container ID.

  1. Create a new tag in Google Tag Manager for the Google Analytics tracking code and configure it with your GA tracking ID.
  2. Publish the container in Google Tag Manager to push the tracking code live on your website.
Exit mobile version