- TLC Home Home
- Discussions & Ideas Discussions & Ideas
- Product Guides Product Guides
- Knowledge Base Knowledge Base
- Developer Docs Developer Docs
- Education Education
- Blog Blog
- Support Desk Support Desk
The Set Data Values extension sets the value of a data layer variable using text, another data layer variable, or JavaScript code.
See the full list of available extensions.
In this article:
Use this extension to set the value of a data layer variable using text, another data layer variable, or JavaScript code. The data layer variable is specified in the Set configuration option, and the new value assigned is specified in the To field. Multiple variables can be assigned in one instance of the extension. An optional condition may be added to control when the value is assigned.
Once the extension is added, the following configuration options are available:
true
for the variables to be assigned new values.This example shows how to set a variable to a text value. In this scenario a condition is used to detect if a query string parameter named q
is populated, then the data layer variable page_type
is set to the text value "search" to indicate that this is a search results page.
page_type
from the the drop-down menu.q (js)
This example shows how to set a variable to the value of another variable. In this scenario, if the variable page_name
does not have a value it is set to the value of the document.title
variable.
page_name
from the the drop-down menu.document title
from the drop-down menu.page_name
.page_name
.page_name
.This example shows how to set a variable to the value returned by a JavaScript statement. In this scenario, the number of search results on a search page is determined by using jQuery to select the number of search result link elements on the page. The variable search_results
is set to the value returned by the JavaScript code.
search_results
from the drop-down menu..length
property: $('.search-results a').length;
.page_type
.Copyright All Rights Reserved © 2008-2022