Can you manually set Analytics events/eVars in SDK event Callback | Community
Skip to main content
isaakskinner
Level 2
August 2, 2023
Solved

Can you manually set Analytics events/eVars in SDK event Callback

  • August 2, 2023
  • 3 replies
  • 4288 views

I was trying to see if it was possible to update the XDM object using the SDK On before event send callback.

I attempted to write the XDM Object with the following code.

Essentially, trying to create some conditional logic to populate eVars in specific instances. 

 

On before event send callback

 

if(digitalData.event.linkClick.href){
content.xdm._experience.analytics.customDimensions.eVars.eVar16 = digitalData.event.linkClick.href;
}

 

Testing in the Network call, i see the customerDimensions.eVars.eVar16 populated, but in the Console, I see an error saying the .analytics objects can't be accessed. 

 

It's likely I am missing something, but wanted to see if I was doing anything that was against what is possible/recomneded.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by leocwlau

The problem is on the left-hand side of the assignment statement, content.xdm._experience.analytics.customDimensions.eVars.eVar16. You can try to print the "content" out in the console as @yuhuisg suggested and you will find there is no "analytics" sub-object under "_experience". The "content" you have in the callback contains only the XDM passing into the sendEvent call instead of a full scheme structure.

It is a practice, when doing value assignments, to check path existence and construct any necessary sub-object leading to the attribute you are assigning.

3 replies

yuhuisg
Community Advisor
Community Advisor
August 3, 2023

Your code looks correct. I've used the on before event send callback too, though not with the "_experience" field group, but I've never encountered this error.

Perhaps you can add a "console.log" in your code to log your content.xdm object at the time that the callback code is run. That may help you to troubleshoot the problem.

leocwlau
Community Advisor and Adobe Champion
leocwlauCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
August 3, 2023

The problem is on the left-hand side of the assignment statement, content.xdm._experience.analytics.customDimensions.eVars.eVar16. You can try to print the "content" out in the console as @yuhuisg suggested and you will find there is no "analytics" sub-object under "_experience". The "content" you have in the callback contains only the XDM passing into the sendEvent call instead of a full scheme structure.

It is a practice, when doing value assignments, to check path existence and construct any necessary sub-object leading to the attribute you are assigning.

Level 3
February 15, 2024

Leocwlau - 

 

Thanks so much for providing an answer on this question.  I have a similar question but it all boils down to how do we replicate the 'doPlugins' functionality with the WebSDK extension. 

 

At first glance it looked like the 'event callback' editor was a solution, but as this post indicated (and correct me if I'm wrong), you can't actually add new variables to an outgoing beacon if the variable is not already part of the outgoing beacon.

My specific uses case is setting 'global variables' as we want to make sure things like page name, page url, and campaign tracking code are on every out going beacon, including the 'track link clicks automatically' beacons (that don't have associated Rules).  Any suggestions on how to solve for my specific scenario?

leocwlau
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
February 17, 2024

Hi @jlinhardt_blueacorn, actually you can. The WebSDK outgoing beacon is indeed sending out the XDM, where you can add any attribute to the XDM in the "before send event callback". The discussion here is just Adobe did not automatically populate the entire XDM structure according to the datatream configuration, however, you are free to add whatever attribute into the outgoing XDM in the callback.

samhollingshead
Level 2
February 19, 2024

@isaakskinner I have answered this on another thread but you are able to achieve this if you merge the content.xdm with your custom xdm object you can then assign values to your custom paths e.g.

 

//Merging the action XDM object with the default XDM object
const globalXdmObject = _satellite.getVar('your custom xdm object');
content.xdm = merge globalXdmObject and content.xdm - you could use something like object.assign()

 

You can then write to the custom.xdm following your custom path e.g.

 

content.xdm.mycustompath.campaigntracking code = 123456;

 

I am wondering on reflection whether this is a bug in the Adobe code where its not recognising extended paths in schemas but the above solution has worked for us.

Level 3
February 19, 2024

@samhollingshead  / @leocwlau 

 

Thanks for getting back to me on my issue here.  I'm afraid, I might be missing something here. 

- We have a 'Global' Data Element which sets our global variables (which campaign tracking code is included).

- We have a 'Variable' Data Element that is referenced in our Rules and sets our 'user action specific' variables. 

- And we have a 'Merge' Data Element that gets brings the two together and is referenced in our 'Send Event' Rule Action tile.

 

Unless I'm missing something, this is what you advised, correct?

 

Unfortunately, we still don't have 'campaign tracking code' being set in the 'Click Data Collection' schema and as such we're not collecting the Campaign Tracking Code when the user clicks on links that don't have an associated Rule, such as downloads and exit links.

 

Any thoughts on why after adding 'campaign tracking code' to our Global Data Element, we're still not able to get 'campaign tracking code' to be added to our 'Click Data Collection' schema? 

 

Am I correct in thinking that the 'Click Data Collection' schema can't be modified?  Meaning it's not referencing our 'Global' Data Element by default, and there is no 'Variable' Data Element nor 'Merge' Data Element being referenced because there is no 'rule' to evoke those elements.    As such, where does the 'Click Data Collection' schema come from and how do I modify it so it includes my custom variable, campaign tracking code?  

 

 

samhollingshead
Level 2
February 19, 2024

Apologies, the code example I added above would be included in the "On before link click send callback" found within the Web SDK extension. You can use your merged data element and combine it with content.xdm this should then populate with your custom variables on the link click.

 

/Merging the action XDM object with the default XDM object
const globalXdmObject = _satellite.getVar('your merged XDM object');
content.xdm = combine globalXdmObject and content.xdm - you could use something like object.assign()

 

As you are already populating campaign tracking code this should now happen automatically but doing the above also gives you the ability to update values at this point in the process as @isaakskinner is looking to do e.g.

 

content.xdm._experience.analytics.customDimensions.eVars.eVar16 = digitalData.event.linkClick.href;