Skip to content

isURL — GTM Variable Template for Condition

VARIABLES › CONDITION
isURL EXTENDED Condition

Checks if the provided value is valid URL.



Examples

Valid URL returns true
INPUT
Value To Check: https://www.example.com
OUTPUT
true
Invalid URL returns false
INPUT
Value To Check: not a url
OUTPUT
false

GTM Configuration

This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.

Read-only Preview
isURL
Value To Check
💾 The value to check.

Supported formats:
  ✓ All
Input Setup
Input Function (optional)
⚙️ Optional pre-processing function applied to the input before internal logic (e.g., convert object to string, normalize case). Internal transformations such as case handling will still apply afterward.
Result Handling
Output Function (optional)
⚙️ Optional function to apply to the result before returning it (e.g., str => str + ' €', val => val !== undefined for boolean conversion). Useful for chaining transformations on the output.


Under the Hood

📜 View Implementation Code
/**
 * Checks if the provided value is a <em>URL</em>.
 * 
 * @param {any} data.src - The value to check.
 * @param {Function|string} [data.out] - Optional output handler: function to transform result or string with format.
 *
 * Direct-mode specific parameters:
 * @param {Function} [data.pre] - Optional pre-processor function to transform `src` before checking.
 * 
 * @returns {boolean} True if the value is a URL, false otherwise.
 *
 * @framework ggLowCodeGTMKit
 */
const parseUrl = require('parseUrl');
const isURL = function(value) {
	return parseUrl(value) !== undefined;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// isURL - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(isURL(value));
// ===============================================================================
// isURL() – Apply Mode
// ===============================================================================
/*
return function(value) {
   return out(isURL(value));
};
*/
🧪 View Test Scenarios (5 tests)
✅ '[example] Valid URL returns true'
✅ Valid HTTP URL with path - should return true
✅ '[example] Invalid URL returns false'
✅ Malformed URL are considered as URL - should return true
✅ Number - should return false