This document describes the properties that can be set for Google Tag Manager variables.
Introduction
Each Google Tag Manager Variable
has a type
code to identify the variable.
In addition, most variables have parameters (key
, type
pairs) that you can set as part of a "parameter object" when you create or
update a variable. To learn more about how to set these parameters using a
parameter object see the
Parameter Reference.
The remainder of this document lists the details of all supported variables.
First Party Cookie
Type code
k
Parameters
Key | Type | Notes |
---|---|---|
name |
template |
Cookie name. |
Example
{ "name": "Sample First Party Cookie Variable", "type": "k", "parameter": [ { "type": "template", "key": "name", "value": "myCookieName" } ] }
Auto-Event Variable
Type code
aev
Parameters
Key | Type | Notes |
---|---|---|
varType |
template |
One of
ELEMENT ,CLASSES , ID ,
TARGET , TEXT , URL ,
HISTORY_NEW_URL_FRAGMENT ,
HISTORY_OLD_URL_FRAGMENT , HISTORY_NEW_STATE ,
HISTORY_OLD_STATE , HISTORY_CHANGE_SOURCE .
|
defaultValue |
template |
Optional. |
Example
{ "name": "Sample AutoEvent Variable", "type": "aev", "parameter": [ { "type": "template", "key": "varType", "value": "CLASSES" }, { "type": "template", "key": "defaultValue", "value": "MyDefault" } ] }
Constant String
Type code
c
Parameters
Key | Type |
---|---|
value |
template |
Example
{ "name": "Sample Constant String", "type": "c", "parameter": [ { "type": "template", "key": "value", "value": "MyString" } ] }
Container Version Number
Type code
ctv
Parameters
N/A
Example
{ "name": "Sample Container Version Number", "type": "ctv" }
Custom Event
Type code
Parameters
N/A
Example
{ "name": "Custom Event Name", "type": "e" }
Custom JavaScript
Type code
jsm
Parameters
Key | Type |
---|---|
javascript |
template |
Example
{ "name": "Sample Custom Javascript", "type": "jsm", "parameter": [ { "type": "template", "key": "javascript", "value": "function() {\n return \"Hello World\";\n}" } ] }
Data Layer Variable
Type code
v
Parameters
Key | Type | Notes |
---|---|---|
name |
template |
Data layer variable name. |
defaultValue |
template |
|
dataLayerVersion |
integer |
1 or 2 . |
Example
{ "name": "Sample Data Layer Variable", "type": "v", "parameter": [ { "type": "template", "key": "name", "value": "DL Variable Name" }, { "type": "template", "key": "defaultValue", "value": "DEFAULT" }, { "type": "integer", "key": "dataLayerVersion", "value": "2" } ] }
Debug Mode
Type code
dbg
Parameters
N/A
Example
{ "name": "Sample Debug Mode Variable", "type": "dbg" }
DOM Element
Type code
d
Parameters
Key | Type | Notes |
---|---|---|
elementId |
template |
|
attributeName |
template |
Optional. |
Example
{ "name": "Sample DOM Element Variable", "type": "d", "parameter": [ { "type": "template", "key": "elementId", "value": "MyElementId" }, { "type": "template", "key": "attributeName", "value": "MyAttributeName" } ] }
HTTP Referrer
Type code
f
Parameters
Key | Type | Notes |
---|---|---|
component |
template |
One of: URL, PROTOCOL, HOST, PORT, PATH, QUERY,
FRAGMENT . |
stripWww |
boolean |
For component = HOST |
queryKey |
template |
For component = QUERY |
Example
{ "name": "Sample HTTP Referrer Variable", "type": "f", "parameter": [ { "type": "template", "key": "component", "value": "URL" } ] }
JavaScript Variable
Type code
j
Parameters
Key | Type | Notes |
---|---|---|
name |
template |
Global variable name. |
Example
{ "name": "Sample Javascript Variable", "type": "j", "parameter": [ { "type": "template", "key": "name", "value": "MyGlobalVarName" } ] }
Lookup Table
Type code
smm
Parameters
Key | Type | Notes |
---|---|---|
input |
template |
Value used for lookup, should be a variable reference. |
map |
list |
A list of maps, each with a single
[key , value ] pair. |
map[].key |
template |
|
map[].value |
template |
|
defaultValue |
template |
Optional. |
Example
{ "name": "Sample Lookup Table Variable", "type": "smm", "parameter": [ { "type": "template", "key": "input", "value": "{{event}}" }, { "type": "list", "key": "map", "list": [ { "type": "map", "map": [ { "type": "template", "key": "key", "value": "EventEqualsThis" }, { "type": "template", "key": "value", "value": "ThenSetToThis" } ] } ] }, { "type": "template", "key": "defaultValue", "value": "MyDefaultValue" } ] }
Random Number
Type code
r
Parameters
N/A
Example
{ "name": "Sample Random Number Variable", "type": "r" }
URL
Type code
u
Parameters
Key | Type | Notes |
---|---|---|
component |
template |
One of: URL, PROTOCOL, HOST, PORT, PATH, QUERY, FRAGMENT .
|
customUrlSource |
template |
Optional. |
stripWww |
boolean |
For component = HOST . |
queryKey |
template |
For component = QUERY . |
Example
{ "name": "Sample URL Variable", "type": "u", "parameter": [ { "type": "template", "key": "component", "value": "URL" }, { "type": "template", "key": "customUrlSource", "value": "{{element}}" } ] }