Has anyone been able to get this to work? I have code that is firing an event and a rule set up with a CustomEvent trigger listening to it. I have tired all sorts of different combinations with no luck. I wrote a listener by hand and it is getting invoked, so I know the event is being fired.
I could never get this to work the way I thought it should in DTM, either, so maybe Adobe and I have different ideas on how to handle events...
Creating the Custom Event (latest browser versions use new CustomEvent(..), but you may need to use different syntax if you are looking for extended backwards compatibility)
Dispatching (triggering) the Custom Event (latest browser versions use elem.dispatchEvent(event), but you may need to use different syntax if you are looking for extended backwards compatibility)
Here is a DTM example for using Custom Events. Below is a similar basic example for Launch. Both of which work for me. So as Jantzen.Belliston mentioned, you will need to provide more info about how you've set it up, including the code you use to create and dispatch the custom event.
This is a generic example, similar to the DTM example above, where I create a custom event listener to be attached to the DOM body. And within the Rule, I just do a simple console.log to show my rule triggered and executed something.
Go to Rules, and click + Add Rule.
For Event Configuration, Select:
Event Type: Custom Event
(and whatever you want for Name and Order)
Then to the right, add the following:
Custom Event Type: MyCustomEvent
Select "specified elements"
Elements matching the CSS selector: body
(everything else default)
Next, under the THEN section, under Actions, click + Add.
Under Action Configuration, select:
Action Type: Custom Code
Name: MyCustomEvent Custom Code
console.log('LAUNCH: Custom Code Box: My Custom Code triggered!');
On the top right of the code box overlay, click Save, then on the bottom right, click Keep Changes.
Then, click Save (or Save to Library and Build if you have a Dev Library selected in the rule). Finally, you will need to go to the build/approval process to deploy to whatever environment(s) in order for the changes to take effect on your site.
This takes care of point #3 in the beginning, where we listen for the custom event.
// generic example for creating the custom event (point #1)
var MyCustomEvent = new CustomEvent('MyCustomEvent');
// generic example for dispatching (triggering) the custom event (point #2)