Skip to content

isUnixTimestampSeconds — GTM Variable Template for Condition

VARIABLES › CONDITION
isUnixTimestampSeconds EXTENDED Condition

Check if the input is a valid Unix timestamp in seconds format.



Examples

Valid seconds timestamp
INPUT
Value To Check: 1609459200
OUTPUT
true
Milliseconds returns false
INPUT
Value To Check: 1609459200000
OUTPUT
false

GTM Configuration

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

isUnixTimestampSeconds
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.
Value To Check number
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
isUnixTimestampSeconds()


Under the Hood

📜 View Implementation Code
/**
 * Checks if the provided input is a valid Unix timestamp in seconds format.
 * 
 * @param {any} data.src - The input value to check (could be a string or number).
 * @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 input is a valid Unix timestamp in seconds format, false otherwise.
 *
 * @framework ggLowCodeGTMKit
 */
const makeInteger = require('makeInteger');
const makeNumber = require('makeNumber');
const isUnixTimestampSeconds = function(value) {
  	if (value === null || value === "") { return false;}
	const valueNum = makeNumber(value);
	const valueInt = makeInteger(value);
	if (typeof valueInt === 'number' && valueNum === valueInt) {
		return valueInt >= -2147483648 && valueInt <= 2147483647;   // Valid range for seconds
	}
	return false;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// isUnixTimestampSeconds - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(isUnixTimestampSeconds(value));
// ===============================================================================
// isUnixTimestampSeconds() – Apply Mode
// ===============================================================================
/*
return function(value) {
   return out(isUnixTimestampSeconds(value));
};
*/
🧪 View Test Scenarios (7 tests)
✅ '[example] Valid seconds timestamp'
✅ '[example] Milliseconds returns false'
✅ String second timestamp - should return true
✅ Decimal timestamp - should return false
✅ Too large timestamp - should return false
✅ Zero Timestamp - should return true
✅ Empty String - should return false