Skip to content

includesAll β€” GTM Variable Template for Array

VARIABLES β€Ί ARRAY
includesAll CORE Array
Direct (.tpl) Apply (.tpl)

Checks if all specified terms are found in the source.


String & Array

Operations that work on both strings and arrays β€” split, join, slice.

Comparison

Test equality, containment, and ordering between values.


All terms found
INPUT
Source Content: The quick brown fox jumps over the lazy dog
Search Terms: ["quick", "fox", "dog"]
OUTPUT
true
Missing term returns false
INPUT
Source Content: The quick brown fox jumps over the lazy dog
Search Terms: ["quick", "fox", "cat"]
OUTPUT
false

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

includesAll
Source Content
πŸ’Ύ The value to search within.

Supported formats:
  βœ“ String: "hello world"
  βœ“ Array: ["a", "b", "c"]
  βœ“ Comma-separated string: "a,b,c"
  βœ“ JSON-stringified array or object: '["a","b"]'
Search Terms
πŸ” Search terms (one or more) to find within the data.

Supported formats:
  βœ“ String: "hello world"
  βœ“ Array: ["a", "b", "c"]
  βœ“ Comma-separated string: "a,b,c"
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.
Source Content array
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
Search Terms array
includesAll()


πŸ“œ View Implementation Code
/**
* Checks if the source contains **all** of the provided search terms.
*
* @param {*} data.src - The data to search within (string, number, object, etc.).
* @param {Array<string>|string} data.tms - Term, array or comma-separated string of terms to search for.
* @param {string|Function} [data.out] - Output handler: function to transform result or string with format.
*
* Direct-mode specific parameters:
* @param {Function} [data.pre] - Optional function to transform `src` before searching.
*
* @returns {boolean} True if all of the terms are found, false otherwise.
*
* @framework ggLowCodeGTMKit
*/
const includesAll = function(searchData, searchTerms) {
if (searchData == null || searchTerms == null) {
return false;
}
const searchString = searchData.toString();
const safeSplit = value => typeof value === 'string' ? value.split(',') : value;
searchTerms = safeSplit(searchTerms);
return searchTerms.every(term => term != null && searchString.indexOf(term) > -1);
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// includesAll - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const searchData = applyCast(data.pre, data.src);
return out(includesAll(searchData, data.tms));
// ===============================================================================
// includesAll(...) – Apply Mode
// ===============================================================================
/*
return function(searchData, searchTerms) {
searchTerms = data.rp1 ? searchTerms : data.tms;
return out(includesAll(searchData, searchTerms));
};
*/
πŸ§ͺ View Test Scenarios (9 tests)
βœ… '[example] All terms found'
βœ… Using comma-separated string for terms
βœ… '[example] Missing term returns false'
βœ… Custom output transformation
βœ… Using pre-processing function on complex source
βœ… Null source data should return false
βœ… Null search terms should return false
βœ… Numeric data gets converted to string for search
βœ… JSON stringified object search