Example: True
triggerView()
call to send a notification to the Target backend for incrementing activity impressions and other metrics.
adobe.target.triggerView("homeView")
Example: False
triggerView()
call to not have notifications sent to the Target backend for impression counting.
adobe.target.triggerView("homeView", {page: false})
Example: Promise chaining with getoffers()
and applyOffers()
To execute triggerView()
when the getOffers()
promise is resolved, it is important to execute triggerView()
on the final block, as shown in the example below. This is necessary for the VEC to detect Views
in authoring mode.
adobe.target.getOffers({
'request': {
'prefetch': {
'views': [{
'parameters': {}
}]
}
}
}).then(function(response) {
// Apply Offers
adobe.target.applyOffers({
response: response
});
}).catch(function(error) {
console.log("AT: getOffers failed - Error", error);
}).finally(() => {
// Trigger View call, assuming pageView is defined elsewhere
adobe.target.triggerView(pageView, {
page: true
});
console.log('AT: View triggered on : ' + pageView);
});
Example: Best compatibility for triggerView()
with the Adobe Visual Editing Helper extension
Consider the following when using the Adobe Visual Editing Helper extension:
Due to Google’s new V3 Manifest policies for Chrome extensions, the Visual Editing Helper extension must wait for the DOMContentLoaded
event before loading the Target libraries in the VEC. This delay might cause web pages to fire the triggerView()
call before the authoring libraries are ready, resulting in the view not being populated on load.
To mitigate this issue, use a listener for the page load
event.
Here’s an example implementation:
function triggerViewIfLoaded() {
adobe.target.triggerView("homeView");
}
if (document.readyState === "complete") {
// If the page is already loaded
triggerViewIfLoaded();
} else {
// If the page is not yet loaded, set up an event listener
window.addEventListener("load", triggerViewIfLoaded);
}