Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!
SOLVED

Call a rule via Custom code of a rule

Avatar

Community Advisor

I was wondering if someone knew of the syntax that would allow me to fire a rule from within the custom code section of a rule.

 

thanks

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@Pablo_Childe 

How about a classic direct _satellite.track call and a rule listening to this direct call event?

 

_satellite.track('contact_submit', { name: 'John Doe' });

 

https://experienceleague.adobe.com/en/docs/experience-platform/tags/client-side/satellite-object

 

Cheers from Switzerland!


View solution in original post

5 Replies

Avatar

Community Advisor and Adobe Champion

While I don't know of code to directly call a rule.... if you have a rule set up to trigger based on a custom JS event, you could call the event from within custom code that would then cause the other rule to trigger, essentially resulting in the same final result....

 

 

 

So for instance, let's say I set up Rule A to trigger based on a custom code listener:

window.addEventListener('myCustomEvent', function (e) {
  trigger();
}, false);

 

 

 

Now, in Rule B, I want to run some logic to trigger Rule A

I'm going to assume that the event "myCustomEvent" isn't declared yet, so I will both declare and dispatch the event inside of Rule B

var myCustomEvent = new Event("myCustomEvent");
window.dispatchEvent(myCustomEvent);

 

As soon as I call the window.dispatchEvent for myCustomEvent, Rule A will trigger.

Avatar

Community Advisor and Adobe Champion

One more thing, for the record, I've never had a lot of luck using the "Custom Event" trigger in Launch... but I've had a lot more success with creating my own listeners, so I've been doing this for years...

 

So following the old adage: "stick with what works"

 

I mention this, cause I figured that will be the follow up comments as to why I didn't just use the Custom Event event type.

Avatar

Community Advisor

Thanks Jennifer

This solution is great in another case for me appreciate the response!

Avatar

Correct answer by
Community Advisor

@Pablo_Childe 

How about a classic direct _satellite.track call and a rule listening to this direct call event?

 

_satellite.track('contact_submit', { name: 'John Doe' });

 

https://experienceleague.adobe.com/en/docs/experience-platform/tags/client-side/satellite-object

 

Cheers from Switzerland!


Avatar

Community Advisor

Thanks Bjoern
I sis happen to have a DCR on that rule so this will work appreciate the response.