Expand my Community achievements bar.

Event Forwarding -question

Avatar

Level 1

Hi All,

I have a issue regarding event forwarding. We are using the Web SDK on our e‑commerce website, and through this interaction call, I am creating a Data Element using the "arc.event.xdm" path name. Now, I need to create another Data Element using Custom Code. How can I build this custom code (using getDataElementValue)?

Example- 

let locale = getDataElementValue('xdm_environment_dc_language');
const match = (typeof locale === 'string') ? locale.match(/-_$/) : " ";
const region = match ? match[1].toUpperCase() : ''
return region;

 
It returns empty string instead of locale value, Anyone from community facing this kind of scenario ?

4 Replies

Avatar

Level 5

Hi @arunkumark2 

 

You can directy reference the XDM in the data element - can you try like below?

 

const locale = arc.event.xdm.environment.dc.language

Don't forgot to publish the dataelement

Avatar

Level 1

Hi @Vinoth_Govind,

The locale variable already holds a value like "en-us", but I need only the second part of the value, i.e., us. Can I use Custom Code to extract just "us"?


Avatar

Level 5

Try this 

 

const match = locale.match(/[_-]([a-zA-Z]{2})$/);
if (match && match[1]) {
  return match[1].toUpperCase();
}
return "";

Above code will work even if value is "us_en". 

Avatar

Administrator

Hi @arunkumark2,

Was the given solution helpful to resolve your query or do you still need more help here? Do let us know. In case the given solution was helpful, then kindly choose it as the 'Correct Reply'.

Thanks!



Sukrity Wadhwa