Expand my Community achievements bar.

Join us in celebrating the outstanding achievement of our AEP Community Member of the Year!

How to update Event in analytics template in XDM custom code section for Update Variable?

Avatar

Level 1

I'm trying to figure out how to update an analytics event, when using the analytics template, within the update variable action.

user10962_0-1734978692597.png

 

I tired something like this:

 

content._experience = content._experience || {};
content._experience.analytics.event1to100 = content._experience.analytics.event1to100 || {};
content._experience.analytics.event1to100.event2.value = 1;

 

But I get an error: Failed to execute "Update variable" for "MY_Test" rule. Cannot set properties of undefined (setting 'value') TypeError: Cannot set properties of undefined (setting 'value')

 

Not sure what I'm missing here? I'm able to update props.

 

content._experience = content._experience || {};
content._experience.analytics.customDimensions.props = content._experience.analytics.customDimensions.props || {};
content._experience.analytics.customDimensions.props.prop1 = "Updated Prop1 Value";
content._experience.analytics.customDimensions.props.prop3 = "Updated Prop3 Value";

Thanks!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Level 1

I figured it out. You have to take it to the specific event:

 

content._experience = content._experience || {};
content._experience.analytics.event1to100.event2 = content._experience.analytics.event1to100.event2 || {};
content._experience.analytics.event1to100.event2.value = 1;

Avatar

Community Advisor

alternatively, skipping the XDM schema, you could also leverage the data.__adobe.analytics object

 

content.__adobe = content.__adobe || { };
content.__adobe.analytics = content.__adobe.analytics || { };
let s = content.__adobe.analytics;
s.events = "events2";

// no linkTrackVars or linkTrackEvents needed

// also, you can set your props here
s.prop3 = "Updated Prop3 Value";

Which approach to choose is a general question to decide on.

I personally try to avoid using the XDM fieldgroup by any means, just because it makes your life so complicated.

Either you come up with data elements for everything or, like in your case, try to fill it with custom code and leaving you with this crazy bloated data structure.

 

Up to you

 

Cheers from Switzerland!