Tracking Code

A tracking code is a small piece of code that is usually implemented as JavaScript in the HTML source code of a website. These lines of code allow advertisers, webmasters and marketers to analyze the flow of visitors to websites and the activities of users. Tracking codes are an important prerequisite for conversion tracking. If appropriate codes are used, the privacy policy will need to be adjusted. Tracking codes should not be confused with tracking parameters attached to the URL.


General Information[edit]

Tracking codes are thematically related to Cookies, Counting pixels and Logfile analysis, and are a prerequisite for analysing visitor behaviour. Tracking codes can be used to retrieve data on website access, traffic, Click Path or other KPIs. In order to track user behavior, the codes must be included in the HTML source code. In order to read out the data, a corresponding software such as Google Analytics account must be linked to the respective website. As a rule, exactly one tracking code is used for each web page and each HTML document regardless of the software used. [1]


Tracking codes are strings of numbers and letters. They are first generated and then inserted into the source code of a web page. This is usually done via a JavaScript-Code, which is executed when the website is called up. The client then sends data such as IP address, clicked URLs or duration of stay to the server or the program used for analysis. A tracking code is usually added to the source code in the head-area]] of the web page to be analyzed.

Other possible functions that a tracking code can perform using appropriate web analytics tools include:

  • Event tracking
  • Measuring the depth of reading
  • Capturing visitor attention with heat-maps
  • Analysis of e-commerce data
  • Control of clicks through advertisements
  • Campaign tracking

Tracking Codes with Google Analytics[edit]

In its latest version, Google Analytics is based on the so-called Global Site Tag, which replaces universal tracking with analytics.js. In addition to the actual tracking of a website, cross-channel and cross-device-tracking as well as event tracking can be carried out.

A tracking code will look like this:

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());
  gtag('config', 'GA_TRACKING_ID');

Die previous Code-Version looks like this:

<!-- Google Analytics -->
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
ga('create', 'GA_TRACKING_ID', 'auto');
ga('send', 'pageview');
<!-- End Google Analytics -->

For a better overview and control of all tags and tracking codes of a website, the Google Tag Manager can be used, for example. This means that the tracking code is not implemented directly in the source code, but is added to the Tag Manager via a web interface.

All newer tracking codes offered by Google load the JavaScript asynchronously, which should not prevent the page from being built.

Tracking codes and data protection[edit]

Using a tracking code has some important consequences which affect data protection and other aspects of the telemedia act. For example, in Germany it has not been decided yet how IP-addresses are allowed to be collected. So the district court of Berlin says it’s illegal without approval of the user while the district court of Munich says the opposite. The question gets answered differently depending on whether the IP-address can be interpreted as personal data or not. A possibility to avoid this problem is to anonymize the IP-address.

If a website uses tracking, they need to inform their user about it according to data protection regulations. They must also be given the opportunity to object to the collection of data. This can be done, for example, in the form of a plugin that prevents tracking.

When using Google Analytics, webmasters should insert an additional line into the code, which transfers the IP address of the user to Google in an anonymous form.

If the Global Site Tag is used, this line is inserted for anonymizing all events:

gtag('config', 'GA_TRACKING_ID', { 'anonymize_ip': true });

If the old code is used, this line will anonymize the IP address:

ga('set', 'anonymizeIp', true);

Implementation in practice[edit]

In order to use tracking codes effectively, some knowledge of HTML and JavaScript is extremely helpful, as integrating the code and the tracking settings is usually a complex process. Often CMS like WordPress or online shop system offer suitable plugins to insert the tracking code with a few clicks in compliance with data protection regulations.

To use tracking codes efficiently a few skills concerning HTML, JavaScript and SEO are very helpful. Especially creating, integrating of codes and adding the tracking are complicated for amateurs. For them, websites that explain step by step how to use tracking codes can be very helpful. Especially important for SEO are those settings: High traffic is preferable, but what about websites that want to generate sales. Then corresponding settings need to be chosen like an e-commerce tracking. The same counts for landing pages that were firstly made to generate leads. So the tracking should work with fixed targets here. For web projects that are only used to inform a usual tracking of the KPIs should be enough. [2]

Significance for Search Engine Optimization[edit]

If you want to run search engine optimization professionally and successfully, you need to know what is happening on your website. Tracking codes in conjunction with web analytics tools are therefore an important prerequisite for the collection of valid data on user behavior, traffic and page performance. Without this data material, for example, the successes or failures of search engine optimization cannot be reconstructed. For SEOs, work usually starts with analyzing a website. The correct implementation of tracking codes on the target page plays a central role.


  1. About properties. Accessed on 04/28/2014
  2. How to Configure & Track Google Analytics Goals for SEO. Accessed on 04/28/2014

Web Links[edit]