Links

Internal variables

These variables are called internal variables because they are created inside the TagCommanders container: They are integrated directly into your site’s container, in contrast with external variables, which are added into the page’s source code by the technical staff.
Internal variables are used to collect data to enrich data through the external variables. A library of predefined internal variables is available, but you can also create your own.
Internal variables must be created in the TagCommander interface before they can be used in containers. See the rest of the articles in the “internal variables” section to know more about the different options available to create such variables.
All internal variables created can be used:
  • To be added to the solutions embedded in the container (linking internal variables and solutions is called mapping). See the “Mapping tags’ variables” article to find out how to map your internal variables in a tag.
  • To create activation rules for your tags. See the “Adding Rules” article to find out how to create rules based on your internal variables.
Additional information
Internal variables are all coded in JavaScript, but you do not need any technical knowledge of JavaScript in order to use the “Predefined” variables or the “Builder” modes, since the code is generated automatically by the TagCommander. However, you will need to know JavaScript or seek help from the Commanders Act support team in order to create your own custom internal variables.
Here are some examples of predefined internal variables:
  • Internal variable for retrieving the URL of the page:
  • Internal variable for retrieving the URL of the previous page/site:
  • Internal variable for retrieving what comes between the first “/” and second “/” of the URL:

When to add an internal variable

There are several situations in which you may need to create an internal variable using the internal variable management interface:
  • You want to retrieve elements available on your web pages, but they do not have external variables implemented by technical staff (for example: the value of a cookie, HTML tag, URL, etc.).
  • You want to create a new variable based on the values of external variables already implemented by technical staff (for example: calculating the cart’s total before tax using the external variable that returns the cart’s total including tax).
  • You want to create a lookup table based on an external variable (for example: when the external “country” variable is “FR”, you send an account number to your analytics tool that is different from when the variable is “IT”).
  • Etc.
The link created between the internal variables and the solutions is called “mapping“. This is performed in the “EDIT” tab during the container deployment process.

Types of internal variables

There are two types of internal variables: predefined and custom.
  • Predefined internal variables, have already been created and are ready to use (e.g. variables that retrieve URL fragments).
  • You can also configure your own internal variables, using pre-existing variables (e.g. external variables) or retrieving elements available on your sites’ pages (e.g. cookies).
To declare a predefined internal variable, click “Options” > “Internal Variables” > “ADD PREDEFINED VARIABLE” (1):
You will then be prompted to select a predefined variable universe.
The “add variable” window contains various fields:
(1) “Predefined universe“: Selection of predefined internal variable categories
(2) “Name“: Variable’s name
(3) “Description“: Variable’s description
(4) “Code“: Variable’s code
(5) Checkbox: The selection of predefined internal variables to add to the container (it is futile to include variables you do not wish to use).
Four predefined variable universes (“Predefined universe”) are available:
  • Common variables: The most used variables by both TagCommander consultants and customers.
  • Customer journey variables: Variables that exploit the visitor’s customer journey (prerequisite: the deduplication module must be activated).
  • AT Internet plugin: Variables that exploit data collected by the AT Internet digital analytics solution (prerequisite: the AT Internet solution must be present on your site).
  • Partner tags: Code snippets adapted and adaptable to partner tags to increase their potential and perform additional actions.

Add build-in internal common variable

You will find below a list of the variables available in the “Common variables” category and their description:
Page title: it stores the title of the page (from the <title> html tag).
Example:
The value of this variable (on the http://www.tagcommander.com/fr/) page will be “Commanders Act – Tag Universel – Tag Management – Commanders Act”. It takes the value of the html <title> tab.
***
Page URL: it stores the URL of the current page.
Example:
The value of this variable for the “http://www.tagcommander.com/fr/” page will be “http://www.tagcommander.com/fr/”
***
Previously Visited URL: it stores the URL of the previous page
Example:
If the visitor arrives at the Commanders Act site via the Google search engine, the value of this variable will contain “google.fr”
***
Page URL without query string: it stores the URL of the current page without the tracking parameters (Commanders Act will remove the “?” from the URL and everything after it.
Example:
If the visitor is on the page “https://www.google.fr/webhp?tab=ww&ei=-ATjVPTyFaWqywOpqoHYDw&ved=0CAcQ1S4#q=inurl&start=10″, the value of this variable will be “https://www.google.fr/webhp”
***
Page query string only: it stores the the current page’s URL parameters (Commanders Act a will save everything that follows the “?” without including it).
Example:
If the visitor is on the page “https://www.google.fr/webhp?tab=ww&ei=-ATjVPTyFaWqywOpqoHYDw&ved=0CAcQ1S4#q=inurl&start=10″, the value of this variable will be “tab=ww&ei=-ATjVPTyFaWqywOpqoHYDw&ved=0CAcQ1S4#q=inurl&start=10”
***
URL parameters: it stores the current page’s array of URL parameters.
Example:
If the visitor is on the page “https://www.google.fr/webhp?tab=ww&ei=-ATjVPTyFaWqywOpqoHYDw&ved=0CAcQ1S4#q=inurl&start=10″, this variable will contain the value of these three parameters: “tab”, “ei” and “ved”, and their values will be accessible in the following manner: “tc_array_url_vars[‘tab’]”, “tc_array_url_vars[‘ei’]” and “tc_array_url_vars[‘ved’]”
***
Folder #1 in URL: it stores the First “folder” in the current page’s URL
Example:
If the visitor is on the page “http://www.tagcommander.com/fr/fonctionnalites/tag-management”, the value of this variable will be “fr”.
***
Folder #2 in URL: it stores the second “folder” in the current page’s URL
Example:
If the visitor is on the page “http://www.tagcommander.com/fr/fonctionnalites/tag-management”, the value of this page will be “fonctionnalites”
***
Folder #3 in URL: it stores Third “folder” in the current page’s URL
Example:
If the visitor is on the page “http://www.tagcommander.com/fr/fonctionnalites/tag-management“, the value of this variable will be “tag-management”
***
Random value(integer 9 digits): it creates and stores a random number composed of 9 digits
Example:
With each pageview/loading of this variable, the variable will return a random 9-digit number; for example, “255103492”
***
URL pathname without query string /…/…/….html: it stores the current page’s URL without the parameters (including the “/”)
Example:
If the visitor is on the page “https://www.google.fr/webhp?tab=ww&ei=-ATjVPTyFaWqywOpqoHYDw&ved=0CAcQ1S4#q=inurl&start=10″, the value of this variable will be “/webhp”
***
Https protocol? “yes”/”no”: Sends “yes” if the page uses the “https” protocol and “no” if it does not
Example:
If the visitor is on the page “https://www.google.fr/webhp?tab=ww&ei=-ATjVPTyFaWqywOpqoHYDw&ved=0CAcQ1S4#q=inurl&start=10″, the value of this variable will be “yes”
***
Current domain name (www.domain.com): it stores the current page’s domain name
Example:
If the visitor is on the page “http://www.tagcommander.com/fr/fonctionnalites/tag-management”, the value of this variable will be “www.tagcommander.com”
***
Main domain name without subdomains: it stores the current page’s domain name without the subdomains
Example:
If the visitor is on the page “http://www.tagcommander.com/fr/fonctionnalites/tag-management”, the value of this variable will be “tagcommander.com”
***
Unix timestamp: Current UNIX time (the number of seconds since January 1, 1970 00:00:00)
Example:
The current UNIX time when this document was written was “142166467”
***
Device: This variable provides information regarding a user’s device based on their screen resolution.

Adding built-in customer journey internal variables

You will find below a list of the variables available in the “Customer journey variables” category and their corresponding description:
Last touch name (channel): Channel of the last touchpoint saved (prerequisite: deduplication must be active on your site).
Example:
For customer journey “SEO/Google -> SEM/Bing -> Display/Criteo” the value of this variable will be “Display”.
***
Last touch name (source): Source of the last touchpoint saved (prerequisite: deduplication must be active on your site).
Example :
For customer journey “SEO/Google -> SEM/Bing -> Display/Criteo” the value of this variable will be “Criteo”.

Adding customer internal variables

You can create your own internal variable in two ways:
  • Via the “Builder” tab: The “Builder” mode assists you in creating customized internal variables without any technical knowledge or expertise;
  • Via the “Custom” tab: “Custom” is a completely customized mode used to write your own JavaScript code. This method requires technical knowledge and expertise (but your TagCommander consultant or support team can create custom variables for you if necessary).
To create your own internal variable, click “Options” > “Internal Variables” > “ADD VARIABLE” (1):
The “add variable” window contains various fields:
(1) “tC.internalvars.“: The variable’s name (caution: it must not contain any accents or special characters, especially “-“).
Note: The variable’s name is always prefixed by “tC.internalvars.” in order to avoid conflict with other variables on your site. For example, to see the content of an internal variable directly on your site or use a variable on another site, do not forget to specify the full name of the variable, which includes the prefix “tC.internalvars.” along with the variable’s name.
(2) “Builder“/”Custom“: Select “Builder” or “Custom” creation mode
(3) Area to create the variable (see details below for the Builder and Custom modes)
(4) “Type“: The type of variable. Please refer to the article “Managing Variable Types“.
(5) “Description“: A description of the variable, to clarify the variable’s name (e.g. “Product IDs separated by a /” can be the description of the variable named “tC.internalvars.concatid”)
(6) “Detailed description“: A detailed description of the variable, to further clarify its name (e.g. “ID1/ID1/ID2…” can be the description of the variable named “tC.internalvars.concatid”)

Builder mode

The “Builder” mode offers you three types of operations (1) that we describe below:
  • “Join internal and/or external variable(s)”;
  • “Join two-dimensional array variable(s)”;
  • “Variable mapping”.

Join internal and/or external variable(s)

This operation allows you to join internal or external variables with the separator of your choice.
Example:
If you wish to join an external variable returning the order ID with another external variable returning the order amount, with everything separated by a “-“, select the “order_id” variable in the “External variables” tab to the left (1) and then enter and add your separator in the “add separator” field (2) in order to finish the “order_amount” variable in the “External variables” tab (1).

Join two-dimensional array variable(s)

This operation allows you to join the array keys of a “Two dimensional array” variable.
Example:
Your retargeting provider wants you to send all the prices of the products added to the cart separated by “|”. Begin by selecting the variable that contains the product information on the cart page (here the “order_products” variable) (1), then the “price” variable (here the “order_product_price” key) (2) and the separator “|” (3). For example, the value obtained might be: “22.50|33.98|94.30”.
CustomVint5

Variable mapping

This operation allows you to create a lookup table for an input value (via an already existing internal or external variable) and an expected output value.
Example:
You want to send a different account ID to your Digital Analytics solution depending on the work environment (pre-prod or prod). Select your reference variable (here the external variable “env_work”), add its different input values in the “INPUT” field (e.g. “pre-prod” et “prod”) (1) and then add the output account IDs of your analytics solution in the “OUTPUT” field (2). You can also add a default value if none of the values entered in the “INPUT” field have been found (3).
This operation allows you to automatically send the correct account ID to your analytics solution depending on the work environment.

Full custom mode

The “Custom” mode allows you to write your own JavaScript code to create the internal variable of your choice:
Note: make sure that the variable’s JavaScript code always has the following syntax:
Also, make sure that %nameVariable% has the same name as the variable entered in the “tC.internalvars” field (see first screenshot with the variable tC.internalvars.mycustomvar):
Note: To avoid potential errors when the internal variable’s code is included, the “TEST” step of the container deployment process will test your internal variable on multiple browsers/operating systems.

Managing variable types

The variable “type” (also called “processing function“) allows you to modify the variable format on the fly when mapping your tags.
They are useful when one of your solutions requests a variable format different from the format that you return in your internal variable. For example, if your “order_discount” variable contains three decimal places, the processing functions will allow you to correct this so that your solutions receive the value with only 2 decimal places.
The most commonly used types are:
  • Order amount: this allows you to modify the number format (amount) on the fly.
You can change separating commas into periods (e.g. “12,50” becomes “12.50”), choose the number of decimal places to retain (e.g. “12.50 becomes “12.5”), or convert the amount into pennies (“12.50 becomes “1250”).
  • Alphanumeric & Special chars: this allows you to modify the character string format on the fly.
You can replace special characters with “_” (e.g. “the company&its values” changes to “the company_its values”) or truncate a character string (e.g. limiting the variable’s value to 10 characters)
After assigning a variable type, you can modify its value on the fly, tag by tag, in the “EDIT” interface. Variables with a type added will have a blue symbol in front of their name (1):
Once you have mapped your variable, click the symbol:
A window will appear with a list of different operations corresponding to the type chosen. Check the operation you want (for example, use only 2 decimal places in the amount) (1) and click “SAVE” (2))

Categorizing internal variables

Since you can create a variable using other variables, it is important for you to be able to manage the order in which they are executed so as to avoid any problems.
Therefore, you must declare an internal variable A, on which an internal variable B is based, before variable B. Variable B needs variable A declared first in order to be executed without creating errors.
The variables’ order can be modified using the double-arrow icon (1):
To categorize an internal variable you must :
  • Click the edit button (pencil icon to the right in the same row where the internal variable is located) and select the type from the drop down menu as depicted below. This applies only when you add a predefined variable.
  • Select the type when you add a custom variable, whether with the “Builder” or ‘Full Custom” mode. (Similar window as the one above).

Declare an internal variable in a container

You can link an internal variable to a container if you have multiple containers on your site.
By doing this action, you declare just once the internal variable code in the linked container(s).
Consequences:
  • You reduce the weight of the other containers by avoiding to declare many times the code of one single internal variable.
  • If you call 2 containers on the same page, you avoid to overwrite the variable value defined in the first container by the value defined in the second container (if the value can change during the page load)
Example: two containers are on the same page, one in the header and one in the body. If you link an internal variable to the header container you will reduce the code of the page as the variable won’t be declared twice, and keep the value of the variable defined in the header.
To link an internal variable to a container, select the container of your choice when you create or modify your variable in the “Declared in container” field (1):
To realize a bulk action on multiple variables, check the variables of your choice (1), then choose the container(s) in the list (2):