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

techtodaypost

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

What Is the Bitcoin Lightning Network?

Bitcoin has established itself as the most popular cryptocurrency. However, its popularity has led to…

2 weeks ago

Opofinance Broker – Does This Forex Broker Have What You Need?

In a market with an average daily trading volume surpassing $6 trillion, the choice of…

3 weeks ago

The Blockchain Bet: How Decentralized Tech is Reshuffling the Deck for Mobile Gambling

High-tech is going through a Renaissance nowadays. For those blissfully unaware, the changes in familiar…

1 month ago

Streamlining Agency Operations: The Role Of Project Management

challenged to deliver high-quality results within short turnaround times. The ability to streamline agency operations…

1 month ago

Empowering HR Teams In The Construction Industry: Tools And Resources For Enhancing Efficiency

Construction projects depend heavily on efficient human resources (HR) operations for their success. HR teams…

1 month ago

SaaS Application Development And The Art Of User Experience Design

The SaaS market is quite competitive these days, which makes it quite a challenge to…

1 month ago