Expand my Community achievements bar.

Help shape the future of AI assistance by participating in this quick card sorting activity. Your input will help create a more effective system that better serves your needs and those of your colleagues.
SOLVED

How to trigger custom event in adobe launch rules

Avatar

Level 5

We have a scenario where a custom event would be triggered. Now I want to fire a tag when the custom event is triggered. What I did is:

  1. Created a new rule.
  2. In events section I used Custom Event from the dropdown.
  3. filled Custom Event Type with email_submit(This is the custom event triggered via $(window).trigger('email_submit')).
  4. In then section I am triggering one of the extensions(DoubleClick Floodlight).

Note: if the use page top event then everything works fine but not with custom event. Please let me know If I am doing something wrong.

1 Accepted Solution

Avatar

Correct answer by
Level 5

For now I have done as below. I will keep on adding all events as I find.

$(window).on('event1 event2 event3',function(e) {

  document.body.dispatchEvent(new CustomEvent(e.type));

});

View solution in original post

17 Replies

Avatar

Community Advisor

There are a few things that I'd try. 

1) I tend to use vanilla JS.  Try one of these (from the JS console) to see if it solves the issue.

Try this if you want to pass a detail payload with the event.

  window.dispatchEvent(new CustomEvent("email_submit", {
  detail: { foo: "1", bar: "2" }
  }));

Or this if you just want the event triggered.

  window.dispatchEvent(new CustomEvent("email_submit"));

Note that if you need to support IE 11, there is a polyfill required for `CustomEvent`.  You'll find it here: https://gomakethings.com/custom-events-with-vanilla-javascript/

2) In DTM, you could not catch a custom event on `window`.  I'm not sure if that's still the case with Launch.

Try dispatching on `body` or any element of your choice.

  body.dispatchEvent(new CustomEvent("email_submit", {

  detail: { foo: "1", bar: "2" }

  }));

You'll need to update your rule in Launch to trigger on `specific element` and `body` as shown below.

Screen Shot 2019-01-08 at 8.48.21 AM.png

Avatar

Level 5

There is a lot of code written with window trigger in analytics. It would be tough to modify all.

It works fine with body custom events.

Also jquery way of triggering custom event is not working

Avatar

Community Advisor

Maybe try `specific elements` and `window`? I haven't gotten around to

trying this in Launch. I'm curious to see if it works for you.

Avatar

Level 5

window doesn't work We are migrating from SIGNAL to LAUNCH. custom window events work fine there but it is not working here.

Avatar

Community Advisor

You could probably create a bit of code that would act as a relay.

I would listen for specific custom events on `window` then re-package and dispatch them on an element of your choice.

Avatar

Level 5

Yeah I can do that but i am not sure how many custom events we have.

Avatar

Correct answer by
Level 5

For now I have done as below. I will keep on adding all events as I find.

$(window).on('event1 event2 event3',function(e) {

  document.body.dispatchEvent(new CustomEvent(e.type));

});

Avatar

Level 4

Curious to know where do you add this? As we are also migrating from signal to launch?

Avatar

Community Advisor

BTW, I spoke with Aaron at Adobe regarding this.  He confirmed that it does not presently work on window (document is the top level object at present).  He confirmed that listening on window would be desirable and that he would make the case for a fix.  At some point in the near future, you should be able to remove that patch and start listening on window.

Avatar

Level 5

Thank you so much for your help and registering the case with window object

Avatar

Employee

> window doesn't work

It's not you, it's us. As @stewarts16448458 noted, we need to fix/improve it on our side and I've logged it internally as an issue.

That said, even when the Custom Event event type begins to support detecting custom events dispatched off the window object, it still probably won't detect events triggered using jQuery (e.g., $(window).trigger('email_submit')). This is because jQuery has its own eventing system that's separate from the native eventing system. Launch only detects events created using the native APIs and doesn't cater to any particular library like jQuery.

Avatar

Level 4

Does  listening on window work now in Adobe Launch ?

 

Does above work? i.e even when the Custom Event event type begins to support detecting custom events dispatched off the window object, it still probably won't detect events triggered using jQuery

Avatar

Community Advisor

I believe Launch's Custom Event event still doesn't work with jQuery's triggered custom events. I assume that this is because jQuery's custom events are not the native Custom Events (reference: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent).

If my assumption is correct, then you will need to make sure you're dispatching Custom Events, not jQuery events, in order for Launch's Custom Event event to detect them.

Avatar

Level 4

Thank you for the confirmation. I will let my developers know to pass the native custom event and then configure the rule in Launch to listen to it.

Avatar

Level 4

What about "window".? Does it work on listening to custom events? Below is an example

window.dispatchEvent(new CustomEvent("email_submit"));

Avatar

Level 5

All our custom events are written in jQuery. Migration is getting tough for us.