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>
window.dataLayer = window.dataLayer || ;<font></font>
gtag(‘js’, new Date());<font></font>
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
ga(‘create’, ‘UA-XXXXXXXXX-Y’, ‘auto’);<font></font>
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
- Copy the tracking code into a new document in a text editor
- Remove <script> and </ script> tags from your tracking code
- Save the file with the same extension as “.js” and the same encoding method as the HTML file of the site.
- Upload 3 files to a suitable directory on your webserver
- Write the following line in the <head> ~ </ head> tags of the HTML source code of all pages.