Advanced State Use Case
In some cases, it is essential to customize a JENTIS State further. The optional properties documented before can be used with the input to the initState function.
Let's run through an example that generates a more enhanced JENTIS State. Here we will activate a JENTIS State for each external data layer item, where we must process each item individually and not from a global perspective.
This is important in situations where JENTIS is loaded asynchronously and accesses a pre-existing data layer. The following might be a simple precondition.
var dataLayer = [{
event: "1"
name: "event_1"
},{
event: "2",
name: "event_2"
}];
If such a dataLayer object is defined before JENTIS is loaded, we must be sure to process each of these events individually. From a global perspective, there is no certain "event" but multiple entries, which might bring us into trouble if we'd like to activate a trigger on the event name "event_1." The array contains two such entries, and we might miss either of them if we do not check each event individually as a JENTIS State.
To resolve this, the contextualStateInformation comes into play. For each JENTIS State, an object with a snapshot of an event can be submitted. Let's give this a try:
function(initState){
//generate this object with the mentioned properties in an appropriate scope
optionalParamObj = {};
//resetting the JENTIS Data Layer is optional in this case, as no further information is pushed this time
optionalParamObj.stateCallback = function() {
window.jentis.tracker.resetDatalayer();
}
for(var i = 0; i < dataLayer.length; i++){
optionalParamObj.contextualStateInformation = dataLayer[i];
initState(optionalParamObj);
}
}
With this example, we execute each entry of the dataLayer (presumably an event object). Now, we can be sure each such external event is translated into a JENTIS State without losing the context (event object).
Now, this would be fruitless if no element took advantage of the contextual object. This can be accessed in frontend variables (custom Javascript variable—Variables).
You can create such a variable and access the corresponding object from a JENTIS State. Which might be the event's "name" value.
function(stateContextObject){
if(stateContextObject.stateContext &&
stateContextObject.stateContext.name)
return stateContextObject.stateContext.name;
else
return undefined;
}
This will return the event's "name" property (from the dataLayer object submitted in the JENTIS State code above).
With this functionality, you can build and customize your JENTIS DCP configuration around all use cases.
Last updated
Was this helpful?