Expand my Community achievements bar.

SOLVED

Any way to have an Event Type be postMessage, or must that be Custom Code?

Avatar

Level 1

Our dev group have found benefits in using the `postMessage` event as a great way to do pub/sub type communication. We'd love to use it in Launch, but don't see a way to make it work outside of Custom Code.  Is Custom Code the only way to do it?

 

It would be great to have an Event Type where we could select `postMessage` and then be asked for a string for it to look for inside of a data, so `siteEventName` in the example below. The data name would need to be standardized on, or also make that something which is configurable when setting it up.

 

 

// equivalent custom code
  window.addEventListener(
    "message",
    function(event) {
      if (event.data.type === "siteEventName") {
        trigger();
      }
    },
    false
  );

// what we would fire in our site code to trigger the event to fire
  window.postMessage(
    {
      type: "siteEventName"
    },
    "*"
  );

 

 

Even better would be to make the additional portions of the data sent to the `postMessage` available to the rule as another Data Type

 

 

  window.postMessage(
    {
      type: "siteEventName",
      foo: "bar",
      hello: "world"
    },
    "*"
  );

 

 

So `foo` and `hello` could be available within a new `postMessage` data type #dreamBig

1 Accepted Solution

Avatar

Correct answer by
Level 4

Use direct call, which can take parameters

View solution in original post

2 Replies

Avatar

Correct answer by
Level 4

Use direct call, which can take parameters

Avatar

Level 10
Do any of the answers below answer your initial question? If so, can you select one of them as the correct answer? If none of the answers already provided answer your question, can you provide additional information to better help the community solve your question?