Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

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

barkeraj
Level 1
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
Haran_Huang
Correct answer by
Level 3
Level 3

Use direct call, which can take parameters

View solution in original post

2 Replies
Haran_Huang
Correct answer by
Level 3
Level 3

Use direct call, which can take parameters

View solution in original post

jantzen_belliston-Adobe
Community Manager
Community Manager
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?