Extracting URL Parameter with GTM and using it as a variable

Update :- now we can get a direct PRE-DEFINED URL VARIABLE as below.  With this, we just have to create a new variable type of URL and component type Query. Query Key here will the name of parameter in the URL.

For above URL the setup extract value of << parm >> will be like below:

 

url_parm

 

 

 

 

 

 

______________________

 

 

 

URL parameter extraction  is very useful in cases when there are restrictions to code directly in the website/application. This implementation will basically need a “Custom HTML” tag and a “Custom JS” variable. So let’s start off.

First make a CUSTOM HTML tag

And make a trigger such that it fires on your target page/s.  This script will extract the URL parameters from URL.

Now create a CUSTOM JS variable:

This will return the URL PARAMETER named “url_parameter”  from CUSTOM HTML tag as VARIABLE and can be use to pass through other tags like conversion tags.