Expand my Community achievements bar.

Get ready! An upgraded Experience League Community experience is coming in January.
SOLVED

How to automatically execute Scripts in Form-Based Activities using Web SDK & Launch?

Avatar

Level 2

 

Hi everyone,

I am migrating from at.js to the AEP Web SDK and trying to replicate a common workflow we used with Form-Based Activities.

The Scenario: In at.js, I could create a Form-Based Activity with a custom mbox location (e.g., my-custom-scope) and return an HTML Offer containing JavaScript (e.g., <script>console.log('test');</script>). This script would execute automatically when the offer was delivered.

The Problem with Web SDK: I am able to successfully fetch the offer using alloy("sendEvent", { decisionScopes: ["my-custom-scope"] }). I can see the HTML content in the propositions payload in the network response.

However, the script inside the HTML offer does not execute automatically.

My Question: What is the best practice in Adobe Launch (Tags) to handle this automatically?

Do I need to manually chain an applyPropositions command after every sendEvent?

Is there a specific configuration in the "Send Event" action within Launch that tells the Web SDK to automatically render/execute scripts found in specific decision scopes?

Or do I need to write a custom "Success" handler rule to parse the propositions and inject the script tags into the DOM manually?

I am trying to avoid writing custom JavaScript handlers for every single form-based activity and want to rely on Launch configuration as much as possible.

Any guidance or screenshots of a Launch Rule setup would be appreciated!

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @shaikhshoeb 

In Form-based Experience Composer, Content delivered to custom scopes is not rendered automatically by the Platform Web SDK. It can be rendered using an action types in Tags (Launch). 

You can modify your page load rule to add a custom decision scope. Add a scope to send event action 

please find the screenshots at below link. 

https://experienceleague.adobe.com/en/docs/platform-learn/implement-web-sdk/applications-setup/setup... 

 

and then process the response from target using applyProposition action type

 

Gokul_Agiwal_0-1764197262134.png

 

 

In case you've several decision scopes that are intended for specific pages, then you should consider using a data element that returns an array of scopes conditionally depending on the page path. 

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @shaikhshoeb 

In Form-based Experience Composer, Content delivered to custom scopes is not rendered automatically by the Platform Web SDK. It can be rendered using an action types in Tags (Launch). 

You can modify your page load rule to add a custom decision scope. Add a scope to send event action 

please find the screenshots at below link. 

https://experienceleague.adobe.com/en/docs/platform-learn/implement-web-sdk/applications-setup/setup... 

 

and then process the response from target using applyProposition action type

 

Gokul_Agiwal_0-1764197262134.png

 

 

In case you've several decision scopes that are intended for specific pages, then you should consider using a data element that returns an array of scopes conditionally depending on the page path. 

Avatar

Level 2

Hi there,

Thank you so much for your input! This was exactly what I needed.

I was able to get it working by chaining the Apply Propositions action after my Send Event.

To handle the <script> tag execution, I configured the Apply Propositions action with:

Selector: body

Action Type: appendHtml

Is this the recommended/correct approach for injecting scripts to ensure they execute immediately? I just want to ensure I’m following best practices by appending it directly to the body.

Thanks again for the help!

Avatar

Community Advisor

Hi @shaikhshoeb  Glad to know that it's working for you and yes it's recommended approach. 

Thank you 🙂