Action Type: Custom Code creates <script> when triggered



I have a rule with the following configuration

  • Event: Core - History Change
  • Action: Core - Custom Code

I realized that the JavaScript custom code is wrapped in a script tag and added to the HTML document. The reason can be found in Rules - Launch, by Adobe.

Is there any way to run JavaScript custom code without it being added to the HTML document?

Accepted Solutions (1)

Accepted Solutions (1)



Hi chuneek49107156,

Because this custom code is not embedded in the library itself (i.e. the rule isn't triggered by 'Page Top' or 'Page Bottom'), you are seeing the results of using postscribe to execute the custom code.  It's also important to know that this code is executed outside of the timing control of Launch (meaning other Rules and Actions may happen before this postscribed code fully completes, yikes! ).

There's no way I could explain it better than Aaronius9er9er9er: So I'd recommend reading his post to grasp how and when postscribe is used. (link below)

Re: Load Order for Rules :: DTM vs. Launch

Other options to avoid the use of Postscribe, and keep the timing control of the execution:

If you are concerned about the code bloating the DOM, or being visible to the user; you still have plenty of options.  One option would be to execute the custom code in the condition section rather than a custom code action block.  Another option (especially if your goal is collecting data for analytics) would be to group this into the specific data elements you plan to use within the "Analytics Set Variables" action block.

There's no single 'best way' or 'standard way' , since all needs and implementations are different - but hopefully this opens up some new possibilities.  If you know exactly what you are doing with the results, that is probably the best place to put this code in a place that's closer to it's use case (like a data element that's referenced in Set Variables).