• Platforms
  • Partners
  • Forums
  • TLC Tealium Learning Center Tealium Learning
    Community
  • Discussions & Ideas Dicussions & Ideas
  • Product Guides Product Guides
  • Knowledge Base Knowledge Base
  • Developer Docs Developer Docs
  • Education Education
  • TLC Blog TLC Blog
  • Support Desk Support Desk
  • CDH Customer Data Hub Customer Data Hub

Table of Contents

  • utag.ut.decode()
  • utag.ut.encode()
  • utag.ut.flatten()
  • utag.ut.hasOwn()
  • utag.ut.isEmpty()
  • utag.ut.isEmptyObject()
  • utag.ut.loader()
  • utag.ut.merge()
  • utag.ut.pad()
  • utag.ut.typeOf()
JAVASCRIPT

Utility Functions

Reference guide for utility functions provided by Tealium for JavaScript.

The following utag.ut functions are available:

Function Description
decode() Returns the decoded value of an encoded URI component or String
encode() Returns the encoded value of a decoded URI component or String
flatten() Returns the flattened value of an object argument
hasOwn() Returns a boolean indicating whether the object has the specified property as its own property
isEmpty() Returns a boolean true indicating the argument is empty, or boolean false if not empty
isEmptyObject() Returns a boolean true indicating the object argument is empty, or boolean false if not empty
loader() Tealium’s tag templates uses this function to load tags (loads iframes, images, scripts and allows for callbacks when a script is loaded)
merge() Merges the properties from one object into another object
pad() Pads a string by adding zeros
typeOf() Returns a variables type as a string

utag.ut.decode()

Returns the decoded value of an encoded URI component or String. This function wraps around the standard JavaScript functions decodeURIComponent() and unescape().

utag.ut.decode(encodedStr)
Parameter Type Description
encodedStr String The encoded string to be decoded

Examples:

utag.ut.decode("Tealium%20Developer%20Docs!");     // "Tealium Developer Docs!"
utag.ut.decode("https%3A%2F%2Fdocs.tealium.com");  // "https://docs.tealium.com"

utag.ut.encode()

Returns the encoded value of a decoded URI component or string. This function wraps around the standard JavaScript functions encodeURIComponent() and escape().

utag.ut.encode(decodedStr)
Parameter Type Description
decodedStr String The decoded string to be encoded

Examples:

utag.ut.encode("Tealium Developer Docs!");   // "Tealium%20Developer%20Docs!"
utag.ut.encode("https://docs.tealium.com");  // "https%3A%2F%2Fdocs.tealium.com"

utag.ut.flatten()

Returns the flattened value of an object argument, delimited by a . character. This function assumes that the object passed is only 1 level deep. The function stops when arriving at a string, array, boolean, or number (float or integer). Do not use this function for multilevel objects or arrays of objects.

utag.ut.flatten(obj)
Parameter Type Description
obj Object The object to be flattened

Example:

utag.ut.flatten({"order_id": "0123567", "cart": {"total_items": 3, "total_amount": 123.45},"order_tax": 9.97});
// {order_id: "0123567", cart.total_items: 3, cart.total_amount: 123.45, order_tax: 9.97}

utag.ut.hasOwn()

Returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it). The function performs a null check and wraps the JavaScript function hasOwnProperty().

utag.ut.hasOwn(obj)
Parameter Type Description
obj Object The object to test

Examples:

var obj = new Object();     // Create an object
obj.x = 3.14;               // Define a non-inherited local property

utag.ut.hasOwn(x);          // true - x is a local property of obj
utag.ut.hasOwn(y);          // false - obj doesn't have a property y
utag.ut.hasOwn("toString"); // false - toString property is inherited from Object

utag.ut.isEmpty()

Returns a boolean true indicating the argument is empty, or boolean false if not empty. It first determines the data type by using the utag.ut.typeOf() function, and returns the following based on the type:

Type Return value description
number Returns the value of the JavaScript function isNaN()
boolean Returns false
String Returns true if the string object’s .length field is 0
Object returns the value of the utag.ut.isEmptyObject() function
utag.ut.isEmpty(arg)
Parameter Type Description
arg [number, boolean, String, Object] The argument to test if empty

Examples:

utag.ut.isEmpty(5);         // false
utag.ut.isEmpty(NaN);       // true
utag.ut.isEmpty(undefined); // true
utag.ut.isEmpty(true);      // false
utag.ut.isEmpty(false);     // false
utag.ut.isEmpty("Tealium"); // false
utag.ut.isEmpty("");        // true

utag.ut.isEmptyObject()

Returns a boolean true indicating the object argument is empty, or boolean false if not empty.

utag.ut.isEmptyObject(obj)
Parameter Type Description
obj Object The object to test if empty

Examples:

utag.ut.isEmptyObject({});              // true
utag.ut.isEmptyObject({ foo: "bar" });  // false

utag.ut.loader()

Tealium’s tag templates uses this function to load tags. It loads iframes, images, scripts and allows for callbacks when a script is loaded. The function only accepts one object argument.

If a file is loaded as an iframe with the same ID as an existing iframe, the function removes the existing element before adding it to avoid impacting browser history and to maintain a cleaner DOM.

utag.ut.loader(object)

The object has the following parameters:

Parameter Description
src URL of the file to load
type The type of tag to load: “iframe”, “img”, or “script” (default)
id (Optional) The element ID
cb (Optional) A callback function
attrs (Optional) An object of additional HTML element attributes

Example:

utag.ut.loader({
  type: "iframe",
  src: "https://example.com/path/file.js",
  id: "teal-tag1",
  cb: function() {},
  attrs: {"async":"true"}})
// Results in the following HTML element:
// <iframe id="teal-tag1"  async="true" height="1" width="1" style="display:none"
//   src="https://example.com/path/file.js"> </iframe>

utag.ut.merge()

Merges the properties from one object into another object. This function does not handle multilevel objects. First flatten the objects before attempting to merge them. This function creates references if used on an array.

utag.ut.merge(obj1, obj2, flag)
Parameter Type Description
obj1 Object The first key-value pair object to merge
obj2 Object The second key-value pair object to merge
overwrite number A flag, 0 (no) or 1 (yes), to overwrite the property value in obj1 from the property value of obj2

Examples:

foo = { "key1":"value1", "key2":"value2" }
bar = { "key1":"value4", "key3":"value3" }
utag.ut.merge(foo, bar, 0)
// foo: {key1: "value1", key2: "value2", key3: "value3"}
// bar: {key1: "value4", key3: "value3"}

foo = { "key1":"value1", "key2":"value2" }
bar = { "key1":"value4", "key3":"value3" }
utag.ut.merge(foo, bar, 1)
// foo: {key1: "value4", key2: "value2", key3: "value3"}
// bar: {key1: "value4", key3: "value3"}

utag.ut.pad()

Returns a number padded with zeros (0).

utag.ut.pad(a, b)
Parameter Type Description
a string The string that you want to pad
b number The total integer length of the string desired after the padding

Example:

utag.ut.pad("Tealium", 10);   // 000Tealium

utag.ut.typeOf()

Returns an argument variables type as a String.

utag.ut.typeOf(arg)
Parameter Type Description
arg Any type The argument to determine the type of

Examples:

utag.ut.typeOf(5);         // "number"
utag.ut.typeOf("Tealium"); // "string"
utag.ut.typeOf(imgObj);    // "htmlimagelement"
utag.ut.typeOf(obj);       // "object"
utag.ut.typeOf(null);      // "null"
utag.ut.typeOf(undefined); // "undefined"
utag.ut.typeOf(obj.cb);    // "function"
Tracking Functions

 
  • Mobile
  • Getting Started
    • Overview
    • Quick Start Guide
    • Mobile Concepts
    • Client-Side
    • Server-Side
    • Tracking Webviews
    • Data Layer
    • Consent Management
    • Event Batching
    • User Location and Geofencing
    • Deep Links
    • Timed Events
    • Trace
    • Hosted Data Layer
    • Feature Comparison
    • Troubleshooting
  • Remote Commands
    • Overview
    • How It Works
    • Integrations
      • AppsFlyer
      • Braze
      • Contentsquare
      • Facebook
      • Firebase
      • Kochava
      • Usabilla
  • Android (Java)
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • Consent Management
    • Module List
      • Ad Identifier Module
      • Crash Reporter Module
      • Install Referrer Module
      • Lifecycle Tracking Module
      • Location Module
      • Optimizely X Tracking Module
    • Android TV
    • Android Wear
    • API Reference
      • ConsentManager
      • DataSources
      • Lifecycle
      • Tealium
      • Tealium.Config
      • TealiumLocation
    • Release Notes
  • Android (Kotlin)
    • Overview
    • Install
    • Track
    • Data Layer
    • Consent Management
    • Identity Resolution
    • Module List
      • Collect Module
      • Collectors Module
      • Crash Reporter Module
      • Install Referrer Module
      • Lifecycle Tracking Module
      • Location Manager Module
      • Tag Management Dispatcher Module
      • Visitor Service Module
    • Android TV
    • API Reference
      • ConsentCategory
      • ConsentManager
      • CurrentVisit
      • DataLayer
      • Lifecycle
      • LocationManager
      • Tealium
      • TealiumConfig
      • VisitorProfile
      • VisitorService
    • Release Notes
  • Cordova
    • Overview
    • Install
    • Track
    • Data Management
    • Module List
      • Ad Identifier Module
      • Crash Reporter Module
      • Install Referrer Module
    • API Reference
    • Release Notes
  • Flutter
    • Overview
    • Install
    • Track
    • Consent Management
    • Data Management
    • API Reference
    • Release Notes
  • iOS (Objective-C)
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • Consent Management
    • Tag Management
    • Module List
      • Lifecycle Tracking Module
      • Optimizely X Tracking Module
    • tvOS
    • watchOS
    • API Reference
    • Release Notes
  • iOS (Swift) 1.x
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • App Extensions
    • Identity Resolution
    • Consent Management
    • Modules
    • Module List
      • AppData Module
      • Attribution Module
      • AutoTracking Module
      • Collect Module
      • Connectivity Module
      • CrashReporter Module
      • DataSource Module
      • DefaultStorage Module
      • Delegate Module
      • DeviceData Module
      • DispatchQueue Module
      • FileStorage Module
      • Lifecycle Module
      • Location Module
      • Logger Module
      • PersistentData Module
      • RemoteCommands Module
      • TagManagement Module
      • VisitorService Module
      • VolatileData Module
    • Feature Comparison
    • Working with Objective-C
    • API Reference
      • TealiumConfig
      • TealiumConsentCategories
      • TealiumConsentManagerDelegate
      • TealiumConsentManager
      • TealiumInstanceManager
      • TealiumPersistentData
      • TealiumVolatileData
      • Tealium
    • Release Notes
  • iOS (Swift) 2.x
    • Overview
    • Install
    • Track
    • Data Layer
    • Consent Management
    • App Extensions
    • Identity Resolution
    • Modules
    • Module List
      • AppData Module
      • Attribution Module
      • AutoTracking Module
      • Collect Module
      • Connectivity Module
      • CrashReporter Module
      • DeviceData Module
      • Lifecycle Module
      • Location Module
      • RemoteCommands Module
      • TagManagement Module
      • VisitorService Module
    • Working with Objective-C
    • API Reference
      • Tealium
      • TealiumConfig
      • TealiumConsentCategories
      • TealiumConsentManager
      • TealiumDataLayer
      • TealiumInstanceManager
    • Release Notes
  • React Native
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • Unity
    • Overview
    • Install
    • Track
    • API Referencee
  • Xamarin
    • Overview
    • Install
    • Track
    • Data Management
    • Consent Management
    • API Reference
    • Release Notes
  • Web
  • AMP
    • Overview
    • Install
    • Track
    • Data Layer
  • Angular
    • Overview
    • Install
    • Track
    • API Reference
  • Google Tag Manager
    • Overview
    • Install
    • Data Layer
  • JavaScript (Web)
    • Overview
    • Install
    • Track
    • Data Layer
    • Universal Data Object (utag_data)
    • Universal Tag (utag.js)
    • Data Layer Object (b)
    • Single-Page Applications
    • Settings
    • Debugging
    • API Reference
      • Cookie Functions
      • GDPR Functions
      • Tracking Functions
      • Utility Functions
    • Release Notes
  • Server
  • C#
    • Overview
    • Install
    • Track
    • Data Layer
    • API Reference
    • Release Notes
  • HTTP API
    • Overview
    • Endpoint
    • Data Layer
  • Java
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • Node
    • Overview
    • Install
    • Track
    • API Reference
  • Python
    • Overview
    • Install
    • Track
    • API Reference
  • Roku
    • Overview
    • Install
    • Track
    • API Reference
  • Ruby
    • Overview
    • Install
    • Track
    • API Reference

Was this article helpful?

This page was last updated: July 16, 2020       Thank you for your feedback!
  • Platforms
  • Partners
  • Forums
  • Mobile
  • Getting Started
  • Remote Commands
  • Android (Java)
  • Android (Kotlin)
  • Cordova
  • Flutter
  • iOS (Objective-C)
  • iOS (Swift) 1.x
  • iOS (Swift) 2.x
  • React Native
  • Unity
  • Xamarin
  • Web
  • AMP
  • Angular
  • Google Tag Manager
  • JavaScript (Web)
  • Server
  • C#
  • HTTP API
  • Java
  • Node
  • Python
  • Roku
  • Ruby