JENTIS Data Layer State
The jts_push_submit(cb)
function is a utility used to intercept and enhance the behavior of the native JENTIS _jts.push()
method. It allows custom logic (like firing callbacks, triggering events, or modifying payloads) to be executed whenever tracking data is pushed to the JENTIS Data Layer.
This is especially useful for extending or customizing the tracking behavior (e.g. triggering beacons, transforming legacy data formats, or resetting the data layer after submission).
Purpose
Wraps the original
_jts.push()
function.Monitors push calls, including special tracking commands like
submit
,event
, andpromotion*
.Executes a callback
cb
when certain conditions are met (e.g. tracking submission).Optionally sends data using the
sendBeacon
method if certain commands are tracked.
Key Behaviors
1. Overwrites _jts.push()
_jts.push()
Saves the original
_jts.push()
tooldFunc
.Replaces
_jts.push
with a new function (newPushFunc
) that includes additional logic before optionally callingoldFunc
.
2. Handles Legacy Promotions
When tracking commands like
promotionclick
orpromotionimpression
are detected,_transformPromotion()
is called.This method reads the last promotion object, transforms it into the current format, and re-pushes it as a
promotion
with the correcttype
.
3. Handles Special Track Commands
The
cb()
callback is invoked when any of the following is true:A
track: "submit"
ortrack: "event"
is pushed.The second argument is
true
(indicating immediate submission).
These are typically moments when all queued data is sent to the server.
4. Supports sendBeacon Requests
If the
track
command is one of the values inarrSendBeaconConfig
(e.g.,addtocart
,event
), the function marks the request assendBeacon
.
Function Breakdown
arrSendBeaconConfig
arrSendBeaconConfig
An array of tracking types that should be sent via the sendBeacon
API for more reliable background delivery.
jsCopyEdit["event", "addtocart", "removefromcart", "addtowishlist", "removefromwishlist", "productlistclick", "promotionclick", "promotionimpression"]
_transformPromotion(promotionType)
_transformPromotion(promotionType)
Transforms legacy promotion*
tracking commands into the modern format and pushes the transformed object to the data layer.
_findElement(arr, target)
_findElement(arr, target)
Simple helper function to check whether a specific value (target
) exists in an array (arr
).
optionalParamObj
optionalParamObj
An object passed to the callback containing:
A
stateCallback
used to reset thewindow._jtsDataLayerContext
.An optional
requestType
(e.g.,sendBeacon
) when applicable.
Initial Data Handling
If the _jts
array already contains items (i.e., data was pushed before the override), they are immediately passed through the new push function to ensure consistent processing.
jsCopyEditif (typeof _jts === "object") {
for (...) {
newPushFunc(_jts[i]);
}
}
Example Usage
You might use jts_push_submit()
to trigger custom logic (e.g., analytics logging or DOM manipulation) every time a submission occurs:
jsCopyEditjts_push_submit(({ stateCallback, requestType }) => {
// Custom logic on submit/event
console.log("Data layer submitted");
stateCallback(); // Reset the current context if needed
});
Summary
The jts_push_submit(cb)
function is a powerful hook into the JENTIS data layer that allows developers to:
Monitor and enhance tracking behavior
Transform legacy tracking formats
Trigger custom logic upon data submission
Utilize modern delivery methods like
sendBeacon
It provides an elegant way to extend the functionality of JENTIS without altering the default data capturing mechanisms.
Last updated
Was this helpful?