Catching Events in Native Javascript

When an event object is pushed onto a data layer array that is managed by Data Layer Manager, an event is dispatched. Data Layer Manager provides an "Event" in Adobe Launch that may be used as a rule trigger. You may find it useful to listen for DLM events from outside of Adobe Launch for any number reasons. If you're here you may have a specific reason in mind.

// Example code for establishing DLM event listeners outside of Launch

// Event handler - called from the listener
var dlmEventHandler = window.dlmEventHandler || function(event) {
  console.log("dlmEventHandler triggered for event:", event);
}

// list of events to listen for
var subscribedEvents = ["SDI-DLM:foo", "SDI-DLM:bar"];

// loop through the list and add a listener for each one
subscribedEvents.forEach(function(subscribedEvent){
  window.removeEventListener(subscribedEvent, dlmEventHandler, false);
  window.addEventListener(subscribedEvent, dlmEventHandler, false);
})

//window.appEventData is the managed data layer
// push a "foo" event
appEventData.push({
  "event": "foo",
  "fooData": {
    "key1": "foo1",
    "key2": "foo2"
  }
})

// push a "bar" event
appEventData.push({
  "event": "bar",
  "barData": {
    "key1": "bar1",
    "key2": "bar2"
  }
})

Here's the same code executed in the console. You'll probably want to do more interesting things than just calling console.log but this should put you on the right track!

Last updated