Technology

How To Insert The Tracking Code On Every Page Of Your Site?

The tracking code displayed after opening an account is a character string of about 10 lines written in a programming language called “JavaScript” and is also called a “tag”. This tag inserts on all pages of the site to be analyzed; this completes the introduction of Google Analytics.

Global Site Tag (gtag.js) Tracking Code

<!– Global site tag (gtag.js) – Google Analytics –>

<script async=”” src=”https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-Y”></script>

<script><font></font>

  window.dataLayer = window.dataLayer || [];<font></font>

  function gtag(){dataLayer.push(arguments);}<font></font>

  gtag(‘js’, new Date());<font></font>

<font></font>

  gtag(‘config’, ‘UA-XXXXXXXXX-Y’);<font></font>

</script>

The part starting with “UA-” is the tracking code. Also known as a “web property ID”. 8: The most important line for various settings of Google Analytics. This line is also responsible for sending page views.

The above tags are called ” Global Site Tags ” of Google Analytics, commonly known as ” gtag.js “, and appeared in beta in August 2017. It became the official version in October 2017, and the insertion location is recommended immediately after the <head> tag (start tag of the head element) of the HTML source.

However, when introducing Google Analytics, inserting tracking code via Google Tag Manager has become almost the de-facto standard. Google Tag Manager has several advantages such as the easy acquisition of data in web analytics.

On the other hand, gtag.js is not recommended to be used via Google Tag Manager, so there is an image that is not widely used. Since there is no data that can only be acquired with gtag.js, there is no reason to actively use it.

Therefore, The most recommended way to implement Google Analytics is to insert the traditional ” universal tag “, commonly known as ” analytics.js “, into every page of the site via Google Tag Manager. 

Also, this book is intended not only for those who are going to introduce Google Analytics, but also for those who have already introduced it, but I think that most of the latter are using analytics.js. The instructions in this document also assume that you are deploying Google Analytics via Google Tag Manager, or that you are inserting analytics.js tags directly into your HTML source.

When inserting the tag of analytics.js directly, get the tag from the official help and rewrite the tracking ID as shown below. The recommended insertion location is just before the HTML source tag (end tag of the head element).

Universal Tag (analytics.js) Tracking code

<script><font></font>

  (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){<font></font>

  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),<font></font>

  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)<font></font>

  })(window,document,’script’,’https://www.google-analytics.com/analytics.js’,’ga’);<font></font>

<font></font>

  ga(‘create’, ‘UA-XXXXXXXXX-Y’, ‘auto’);<font></font>

  ga(‘send’, ‘pageview’);<font></font>

</script>

The part starting with “UA-” is the tracking ID. Rewrite to the property of your own site. 8: send command. Send the pageview of the tagged page to Google Analytics.

Add analytics.js to your site

You can paste the tracking code into the HTML source of the page as it is, but it is also effective to put it in one file as an external file and write JavaScript to read that file in HTML. If you need to change your tracking code, you can modify one file to cover all pages. The method is as follows.

  1. Copy the tracking code into a new document in a text editor
  2. Remove <script> and </ script> tags from your tracking code
  3. Save the file with the same extension as “.js” and the same encoding method as the HTML file of the site.
  4. Upload 3 files to a suitable directory on your webserver
  5. Write the following line in the <head> ~ </ head> tags of the HTML source code of all pages.

Also Read : How To Register A Website In Google Search Console

Admin Team

Tech Today Post is an online international journal for all the latest technology news & updates. We also write about Digital Marketing, Business, Software and Gadgets.

Recent Posts

How Rankings.io Supports Law Firms in Digital Growth

In today’s competitive legal market, simply being qualified and experienced isn’t enough — potential clients…

2 days ago

The Power of Words: How NicePhrase.com Helps You Express Every Emotion Effortlessly

Words help shape our relationships in any conversation, caption, or message. The right phrasing may…

1 week ago

Can An Office Fitout Encourage Team Bonding?

Did you know that the way an office is laid out can do a lot…

1 week ago

Tips to Manage Data in Your Business

The world of data can be an overwhelming and stressful environment for business owners, and…

2 weeks ago

The Quiet War Over LinkedIn Data Access—and What It Means for Tomorrow’s AI Tools

LinkedIn has emerged as a valuable resource for both professionals and companies alike. A vast…

3 weeks ago

Qoruv.com Pioneering Firm: Leading Digital Transformation with Innovative Solutions

In the rapidly-moving digital age, companies must leverage technology to stay competitive. Qoruv.com, a Pioneering…

4 weeks ago