0

I am trying to add a trigger on adobe launch to fire a rule when the site has a specific data layer event.

I did it in the past to fire a rule when someone clicked three times on the site:

window.addEventListener('click', function (event) { 
  If (event.detail === 3) {
     trigger();
});

, but I'm lost in archiving it with data layer events. I will intend to create a listener to fire the rule on the event "show" from this data layer object:

window.adobeDataLayer = window.adobeDataLayer || [];
window.adobeDataLayer.push({
    "event": "show",
    "eventInfo": {
        "reference": "component.accordion-1-item-2"
    },
    "component": {
        "accordion-1": {
            "shownItems": [
                "component.accordion-1-item-1",
                "component.accordion-1-item-2"
            ]
        }
    }
});
Blacklover
  • 15
  • 2
  • btw I know I can fire the rule with an extension, but I want to do it this way to fire the same rule in more than one event with just one custom code. I'll use regex to fire the rule in event1|event2|event3. thanks, guys :) – Blacklover Sep 08 '22 at 11:46

1 Answers1

1

First of all, writing custom listeners for DL is very rarely a good idea. Because it requires quite solid knowledge of nuances in TMSes operations.

I would suggest using the extension. That would likely be either ACDL (Adobe Client Data Layer) or DM (Datalayer Manager). I suggest ACDL as native to Launch. In fact, I think you're using ACDL since what you have is ACDL's default name for the DL.

So, let's do exactly what you want without having to touch the DL listener. Here we're using ACDL and making a new trigger: enter image description here

Note that we have it firing on all events.

Now we do a simple hack in a condition (Core -> Custom Code), having a regex there exactly as you want it:

return /myevent/i.test(event.message.event);

Finally, testing our work:

enter image description here

If you still want to have your DL listener (you should not), you can do that, certainly. TMSes and extensions do that through overriding the DL's push method, here:

y.push = function(t) {
  var e = arguments
    , r = arguments;
  if (Object.keys(e).forEach((function(t) {
      var o = a(e[t]);
      switch (o.valid || (p(o),
      delete r[t]),
      o.type) {
      case s.itemType.DATA:
      case s.itemType.EVENT:
          n(o);
          break;
      case s.itemType.FCTN:
          delete r[t],
          n(o);
          break;
      case s.itemType.LISTENER_ON:
      case s.itemType.LISTENER_OFF:
          delete r[t]
      }
  }
  )),
  r[0])
      return Array.prototype.push.apply(this, r)
}

Feel free to add your overridal on top of that.

BNazaruk
  • 6,300
  • 3
  • 19
  • 33
  • And If I would like the CORE-CUSTOM code been fire in this 3 events: Purchase,addtocard and iniciatecheckout, how should be the custom code??? thx @BNazaruk – Blacklover Sep 08 '22 at 16:49
  • `return /purchase|addtocart|iniciatecheckout/i.test(event.message.event);` – BNazaruk Sep 08 '22 at 20:15