This article describes the Pathname Tokenizer extension and provides a usage example.
See the full list of available extensions.
In this article:
The Pathname Tokenizer extension uses the page variable
location.pathname to create up to eight new data layer variables, each representing a section of the URL pathname. This extension can reduce the amount of development work typically needed to update your data layer and is especially helpful for websites with descriptive pathnames.
Here's how it works:
location.pathnameand separates each text value between the slash ("/") characters. Example:
Any website can use the pathname tokenizer, but sites with a logical and consistent structure reflected in the URL pathname will benefit most from this extension. This example is based on an e-commerce clothing site where the pathname values represent the site section, categories, and sub-categories of the site structure.
Here are a selection of URLs that might exist on the example site:
Page 1 - https://example.com/apparel/ Page 2 - https://example.com/apparel/women/ Page 3 - https://example.com/apparel/women/jeans/ Page 4 - https://example.com/apparel/women/jeans/skinny-jeans/
When the pathname tokenizer extension runs, the pathname is split into individual variables, one for each segment. The generated
_pathname# variables will be different from page to page depending on the pathname of each URL.
This table shows the resulting values generated by the extension for each example URL above. You can see how you could use these variables to represent the structure of the site in your data layer.
To give the pathname variables more meaningful names, use the Set Data Values extension to copy the pathname variables into new variable names, such as
For example, you could copy
site_subcategory , and
site_subcategory2 , and so on.
|Variable||Value on Page 1||Value on Page 2||Value on Page 3||Value on Page 4|