Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experience Fragment enhancement to allow remote offer from Adobe Target #1424

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
fieldDescription="HTML ID attribute to apply to the component."
fieldLabel="ID"
name="./id"/>
<useFragmentAsRemoteOffer
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
fieldDescription="When checked, the experience fragment can be used as a remote offer and the experience can be replaced with a different content from Adobe Target using the id provided above."
name="./enableRemoteOffer"
text="Enable Remote Offer with Adobe Target"
value="{Boolean}true"/>
</items>
</column>
</items>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
data-sly-set.selector="content.${request.requestPathInfo.selectorString}"
data-sly-resource="${@path=fragment.localizedFragmentVariationPath, selectors=selector, wcmmode='disabled'}"
id="${component.id}"
class="cmp-experiencefragment cmp-experiencefragment--${fragment.name}">
class="cmp-experiencefragment cmp-experiencefragment--${fragment.name} ${properties.enableRemoteOffer ? ' mboxDefault' : ''}">
</div>
<sly data-sly-call="${template.placeholder @ isEmpty=!fragment.configured, classAppend='cmp-dd-experiencefragment'}"></sly>
<sly data-sly-call="${template.placeholder @ isEmpty=!fragment.configured, classAppend='cmp-dd-experiencefragment'}"></sly>

<script data-sly-test="${properties.enableRemoteOffer && properties.id}" data-sly-set.mboxId="${properties.id}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we moved the script to a clientlib instead of inlining it. It could activate on page load and process all elements that have a certain data attribute (for example: data-enable-remote-offer).

Also, shouldn't the mboxId leverage component.id instead o properties.id. It's a subtle difference but sometime they could be different.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladbailescu I have moved the inline scripts into clientlib and added the data-attibutes.

Explicetely we are reading the mboxId from properties.id because that field is optional and if someone does not want to use the experience targeting offer, they will not configure the field in which case the backend sling model will generate a random id and which we do not want to use for target. So if any customer wants to use the target offer they will need to provide an id explicitly and the same will be used by both component.id and properties.id

adobe.target.getOffer({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make sure the global adobe.target is available before calling getOffer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladbailescu added the check to make sure adobe.target is available before it's called.

mbox: "${mboxId @ context='scriptString'}",
success: function (offer) {
adobe.target.applyOffer({
mbox: "${mboxId @ context='scriptString'}",
selector: "#${mboxId @ context='scriptString'}",
offer: offer
});
},
error: function (error) {
var el = document.getElementById("${mboxId @ context='scriptString'}");
el.style.visibility = "visible";
}
});
</script>