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

barkeraj

24-02-2020

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

Accepted Solutions (0)