Hi there,
I am trying to use Event Forwarding to send data to other systems dynamically. The scenario is multi-brand, so I have different XDM schema fields referring to the same concept (e.g.: identities.brand1.ecid, identities.brand2.ecid). I want Event Forwarding to adapt the request depending on the origin (brand) of the data, so I have decided to create a dynamic Data Element via custom JS code:
let ecid;
var xdmObject = getDataElementValue('arc.event.xdm');
if(xdmObject){
if (url.includes("brand1.com")) {
ecid = xdmObject._sandboxname.identities.brand1.profile.ecid.id;
} else if (url.includes("brand2.com")) {
ecid = xdmObject._sandboxname.identities.brand2.profile.ecid.id;
} else {
// Handle cases where the URL does not match any known hosts
console.warn('Unknown host in URL:', url);
ecid = "";
}
}
return ecid
Nevertheless, when I try to Build the code I get the next error:
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @jlasso71
arc.event.xdm is actually a path to the request payload. Have you created a data element with exactly this name?
If so, make sure to include it in your Library.
If you are just using custom code, you won't need to pull this data element in, since you can just directly reference it from your custom code.
arc.event.xdm.path.to.data
Just beware that you must make sure your code checks for anything being unset in your object structure.
Luckily, nowadays, this is pretty easy in Javascript and you can use Optional Chaining to access anything at any depth in your object structure, by using "?." instead of "." to access the next level. As soon as any part is not set, it will stop executing and not fail.
// the old world
if (arc && arc.event && arc.event.xdm && arc.event.xdm._sandboxname && arc.event.xdm._sandboxname.identities
&& arc.event.xdm._sandboxname.identities.brand1 && arc.event.xdm._sandboxname.identities.brand1.profile
&& arc.event.xdm._sandboxname.identities.brand1.profile.ecid && arc.event.xdm._sandboxname.identities.brand1.profile.ecid.id) {
// boy this is long!
}
// the new world
if (arc?.event?.xdm?._sandboxname?.identities?.brand1?.profile?.ecid?.id) {
// much better
}
In other words, if you were accessing arc.event.xdm.hello.world through code, and any part of this path is not set, you would get an error.
So, if you know already that you have a specific number of brands, maybe you are better off with creating dedicated data elements
since access to this Path is implicitly failsafe.
Views
Replies
Total Likes
Hello @jlasso71 You can create rules.
First store the the value of URL in a data element like this:
Then create a URL to check the value and fire the custom code
Views
Replies
Total Likes
Hi Manoj,
Thanks for your prompt response. Your solution makes sense but it requires one rule per brand (I have more than 20 brands in some cases). Also, I would need a Data Element per each XDM path, which is something I would definitely like to avoid.
Have you tried to access "arc.event.xdm" directly from Event Forwarding custom code?
Best regards,
Views
Replies
Total Likes
Hi @jlasso71
arc.event.xdm is actually a path to the request payload. Have you created a data element with exactly this name?
If so, make sure to include it in your Library.
If you are just using custom code, you won't need to pull this data element in, since you can just directly reference it from your custom code.
arc.event.xdm.path.to.data
Just beware that you must make sure your code checks for anything being unset in your object structure.
Luckily, nowadays, this is pretty easy in Javascript and you can use Optional Chaining to access anything at any depth in your object structure, by using "?." instead of "." to access the next level. As soon as any part is not set, it will stop executing and not fail.
// the old world
if (arc && arc.event && arc.event.xdm && arc.event.xdm._sandboxname && arc.event.xdm._sandboxname.identities
&& arc.event.xdm._sandboxname.identities.brand1 && arc.event.xdm._sandboxname.identities.brand1.profile
&& arc.event.xdm._sandboxname.identities.brand1.profile.ecid && arc.event.xdm._sandboxname.identities.brand1.profile.ecid.id) {
// boy this is long!
}
// the new world
if (arc?.event?.xdm?._sandboxname?.identities?.brand1?.profile?.ecid?.id) {
// much better
}
In other words, if you were accessing arc.event.xdm.hello.world through code, and any part of this path is not set, you would get an error.
So, if you know already that you have a specific number of brands, maybe you are better off with creating dedicated data elements
since access to this Path is implicitly failsafe.
Views
Replies
Total Likes
Hi @bjoern__koth ,
Thanks for your response, your solution using Optional Chaining is really powerful. The problem we have is that when accessing arc.event.xdm.hello.world through code we are not even able to publish the changes:
Regarding using failsafe data elements, we do not want to create dedicated data elements per brand due to operative costs (20-30 brands * 5-10 paths = 100-300 data elements).
Best regards,
Views
Replies
Total Likes
Can you post your code or screenshot of it? Should be an easy explanation for the error.
if you don't want to share the code publicly, you can also send me a DM
Views
Replies
Total Likes
@jlasso71 as you may have noticed, this was me from my phone but obviously a different account above xD
If you want to share your code with me, drop me a DM
Views
Replies
Total Likes
Views
Likes
Replies