Data and properties in the _st module
The _st module includes methods for reading and writing tag properties, managing user data, and working with markers and counters. Use these methods after the base script has loaded to interact with the data layer directly.
If you need to queue commands before the script has loaded, use the async command queue instead.
Methods overview
_st.data methods
Method | Description |
|---|---|
| Gets a tag property by name. |
| Gets an array of all tag property names. |
| Gets an array of all local tag property names. |
| Appends a single value to a local array property. |
| Returns the current user data object. |
| Initializes the data module by reading data from the user cookie. |
| Saves the current user data object to the cookie. |
| Resets all remote properties. |
| Gets a specific marker from a group. |
| Gets all markers in a group. |
| Sets a marker. |
| Removes a specific marker from a group. |
| Resets all markers for a group. |
_st.counter methods
Method | Description |
|---|---|
| Calls and increments the specified counter. |
Method details
_st.data.getProperty(name, defaultValue)
Gets a tag property by name. The system checks local tag properties first, then remote tag properties. If the property isn't set in either, the method returns an empty string, or the optional defaultValue if provided.
Parameters:
name (string): The name of the property.
defaultValue (any, optional): The value to return if the property isn't set.
_st.data.getPropertyNames()
Gets an array of all tag property names (_tagProperties). Note that returned property names aren't necessarily URL-safe.
_st.data.getLocalPropertyNames()
Gets an array of all local tag property names (_localTagProperties). Note that returned property names aren't necessarily URL-safe.
_st.data.addLocalArrayProperty(propertyName, value)
Appends a single value to a local array property. If the array does not yet exist for the given property name, it is created automatically. Use this to build structured lists of data incrementally, such as adding multiple products to a cart.
Parameters:
propertyName (string): The name of the array property.
value (any): The single value to append to the array.
Example:
// Adds items to the 'products' array one by one
_st.data.addLocalArrayProperty('products', 'productA');
_st.data.addLocalArrayProperty('products', 'productB');_st.data.getUserData()
Returns the current internal user data object parsed from the cookie. This object contains the user's active markers, active experiments, cookie consent preferences, and opt-out statuses.
_st.data.init()
Initializes the data module by reading data from the user cookie (expected to be a URI-encoded JSON object). During initialization, the system also evaluates and automatically prunes any expired markers.
_st.data.saveUserData()
Saves the current state of the user data object to the cookie. The data is JSON-encoded and URI-escaped before saving.
_st.data.resetRemoteProperties()
Resets all remote properties. Local properties are not affected.
_st.data.getMarker(groupName, markerName)
Gets a specific marker by name from a group.
Parameters:
groupName (string): The group to look in.
markerName (string): The name of the marker.
Returns: The expireTimestamp of the marker, or undefined if the marker isn't set.
_st.data.getMarkers(groupName)
Gets all markers in a group.
Parameters:
groupName (string): The name of the group.
_st.data.setMarker(markerGroup, markerName, expireTimestamp)
Sets a marker in a group.
Parameters:
markerGroup (string): The group in which to set the marker.
markerName (string): The name of the marker to set.
expireTimestamp (integer): The Unix timestamp (in milliseconds) at which the marker expires.
_st.data.removeMarker(groupName, markerName)
Removes a specific marker from a group.
Parameters:
groupName (string): The group to remove the marker from.
markerName (string): The name of the marker to remove.
_st.data.resetMarkers(markerGroup)
Resets all markers for a group.
Parameters:
markerGroup (string): The group whose markers you want to reset.
_st.counter.call(counter)
Calls and increments the specified counter. The counter must be configured in the Data Activation interface before use.
Parameters:
counter (string): The ID of the counter as set in the interface.