Tracking Code

A tracking code is a small snippet 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 and attribution. 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 log file analysis, and are a prerequisite for analyzing visitor behavior. 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 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]

Functions of a Tracking Code[edit]

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 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 the appropriate web analytics tools include:

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

Tracking Codes with Google Analytics[edit]

The latest version of Google Analytics is based on the so-called Global Site Tag, which replaced universal tracking with analytics.js. In addition to tracking a website, the Global Site Tag allows for cross-channel tracking, cross-device tracking, and event tracking. 

The current Google Analytics tracking code looks like this:

<!-- Global Site Tag (gtag.js) - Google Analytics -->

The previous Google Analytics  tracking code looked like this:

<!-- Google Analytics -->

<!-- End Google Analytics -->

Google Tag Manager can be used to get a better overview and have greater control of all tags and tracking codes on a website. 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 that 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 useful, as integrating the code and the tracking settings is usually a complex process. Often CMS like WordPress or online shop systems 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 HTML, JavaScript Search Engine Optimization (SEO) skills are very helpful. Creating, adding, and integrating tracking codes and can be complicated for amateurs. Beginners may want to consult websites that explain how to use tracking codes step-by-step.  Websites that generate sales need to implement settings for e-commerce tracking. The same counts for landing pages that were first made to generate leads. Tracking should work with fixed targets here. Usual KPI tracking should be enough for web projects that are only used to inform.


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 attributed. For SEOs, work usually starts with analyzing a website. The correct implementation of tracking codes on the target page plays a central role in the development of an SEO strategy and reporting of marketing support. 


  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]