Manual: TrueDirect custom dimension

The instructions below are an experimental solution for the issue of TrueDirect traffic and the campaign timeout that we are currently developing and improving. When using this custom dimension, we recommend testing among other things the impact on web load time.

E-commerce Academy s.r.o. and Miroslova Pecka assumes no liability for any damages caused by the implementation of the custom dimension by manuals on this site.

By implementing a custom TrueDirect dimension to Google Analytics using the Google Tag Manager, you can use the Marketing Attribution Tool to easily calculate Data Driven Attribution with advanced setup and use of actual "Direct / (none)" calculations.

The advantage of the TrueDirect custom dimension compared to the "Driect Session" secondary dimension, which is already a standard part of Google Analytics, is the ability to download actual Direct / (none) traffic from the Google Analytics API, which is a prerequisite for subsequent use of this information for calculations and visualizations outside the GA interface.

Author: Miroslav Pecka

  • The author of the script below is a web consultant and web analyst Miroslav Pecka (

  • We would like to thank Mirek for the whole team of for helping us to solve the issue of true direct traffic in Google Analytics and setting the campaign timeout and experimenting with them.

How to implement TrueDirect custom dimension

in 2 steps (implementation time: 5 minutes)

1. Set up a custom dimension in Google Analytics

  • To create a new custom dimension in Google Analytics, you must have editing rights to the desired GA account.

  • Then, in the Settings tab of the “Property” column, click “Custom dimensions” -> “New custom dimension”.

1.1 Creating a "TrueDirect" dimension in Google Analytics

1.2 Final form for custom custom dimension

  • Pay attention to the correct setting of the scope of the new dimension

    • GATDR = session scope

      • GATDR = abbreviation for Google Analytics TrueDirect​

    • For correct setting in GTM (see below), note the index of the created dimension, in my case:

      • GATDR = 3

2. Set “TrueDirect” in Google Tag Manager

To set up GTM to send with each visit information about whether or not it was "TrueDirect" is very simple (you will also find a picture tutorial below the text):


  1. Create a "Custom JavaScript Variable" that will be called "Script GA True Direct Reveal".

  2. Insert the script below:

    • function() {
      Copyright (C) Miroslav Pecka (  
      This work is licensed under CC BY-SA 4.0 License. (
      "use strict";
      /* Settings */
      var settings = {
          hostnames: "", // website domain or comma separated list of domains
          sessionDuration: 30, // minutes
          debug: true
      /* Do not edit below */
      var GATDR={sessionDuration:settings.sessionDuration,hostnames:settings.hostnames,cookieName:settings.cookieName||"WAS_GATDR",debug:settings.debug||!1,label:{yes:"Yes",no:"No"},setCookie:function(e){var i=new Date;return i.setTime(i.getTime()+6e4*this.sessionDuration),document.cookie=this.cookieName+"="+e+";path=/;expires="+i.toGMTString(),e},getCookie:function(){var e=document.cookie.match("(^|;) ?"+this.cookieName+"=([^;]*)(;|$)");return e?e[2]:null},referrerDomain:function(){return document.referrer.split("/")[2]},isSelfReferral:function(){return this.hostnames.split(/, */).includes(this.referrerDomain())},isDirect:function(){return void 0===this.referrerDomain()||this.isSelfReferral()?},evaluate:function(){var e=[["isDirect",this.isDirect()],["isSelfReferral",this.isSelfReferral()],["refererDomain",this.referrerDomain()],["referer",document.referrer],["getCookie",this.getCookie()]];if(this.debug&&console.table(e),null==this.getCookie())this.setCookie(this.isDirect());else{var i=this.getCookie();i==this.label.yes&&this.isDirect()}return this.getCookie()}};
      return GATDR.evaluate();

    • }

  3. Insert the correct domain in the script, see the red text above.

  4. We recommend to keep session duration in Google Analytics default = 30 minutes.

  5. Consequently, you only need to modify your "Google Analytics variable", which you are currently sending to GA (you do not create a new tag).

    • Scroll to the desired Variable ->

    • Add a new Custom Dimension that you created in Google Analytics (with the correct number, in my case 3).

    • For Dimension Value, insert {{Script GA True Direct Reveal}}.

The result of a true TrueDirect custom dimension implementation

All done :-)

Something from the manual is not understandable or does it not work?
Send us a message.

©2019, created with love by Marek & Milan