User metadata "template" for digitalData | Community
Skip to main content
Level 2
July 7, 2020
Solved

User metadata "template" for digitalData

  • July 7, 2020
  • 1 reply
  • 1293 views

Hi.

 

My client's website contains several web apps developed by separate teams. As the apps grow, the teams want to record new data about users, e.g. "unread messages", "new notifications", "qualifies for xyz" and so on.

 

I'd like to avoid adding new eVars/sProps every time a new piece of metadata comes along.

 

Does anyone have a clever way of implementing this? Either by:

 

- a digitalData.user schema that's flexible enough to be reused for most needs

- a way in which we can add key-value pairs to a single eVar/sProp and convert each pair into a new dimension

 

Any suggestions would be appreciated. 🙂 Cheers.

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 Alexis_Cazes_

Code

 

//Data layer Example var digitalData = { "user": { "attributes": { "unreadMessages": 2, "notifications": 5, "isXyz": true } } } //Methods to add in custom code of Adobe Analytics extension var getUserAttributes = function () { try { _satellite.logger.log('[Adobe Analytics] Building user attributes details'); return buildStringFromMap(digitalData.user.attributes); } catch (e) { _satellite.logger.error('[Adobe Analytics] Failed to build user attributes details -- ' + e); } } var buildStringFromMap = function (map) { try { var output = ''; for (var key in map) { var value = map[key]; if (typeof value == 'boolean') { value = value ? 1 : 0; } if (value instanceof Array && value.length > 0) { value = value.toString(); } output += value ? key + '=' + value + '|' : ''; } return output; } catch (e) { _satellite.logger.error('[Adobe Analytics] Failed to build string from map -- ' + e); } } //In Adobe Analytics doPlugins function s_doPlugins(s) { s.eVarX = getUserAttributes(); //should return unreadMessages=2|notifications=5|isXyz=1| }

 

 

 

Now in your report you will see line items as unreadMessages=2|notifications=5|isXyz=1|

 

Next Steps:

1 reply

Alexis_Cazes_
Alexis_Cazes_Accepted solution
Level 10
July 7, 2020

Code

 

//Data layer Example var digitalData = { "user": { "attributes": { "unreadMessages": 2, "notifications": 5, "isXyz": true } } } //Methods to add in custom code of Adobe Analytics extension var getUserAttributes = function () { try { _satellite.logger.log('[Adobe Analytics] Building user attributes details'); return buildStringFromMap(digitalData.user.attributes); } catch (e) { _satellite.logger.error('[Adobe Analytics] Failed to build user attributes details -- ' + e); } } var buildStringFromMap = function (map) { try { var output = ''; for (var key in map) { var value = map[key]; if (typeof value == 'boolean') { value = value ? 1 : 0; } if (value instanceof Array && value.length > 0) { value = value.toString(); } output += value ? key + '=' + value + '|' : ''; } return output; } catch (e) { _satellite.logger.error('[Adobe Analytics] Failed to build string from map -- ' + e); } } //In Adobe Analytics doPlugins function s_doPlugins(s) { s.eVarX = getUserAttributes(); //should return unreadMessages=2|notifications=5|isXyz=1| }

 

 

 

Now in your report you will see line items as unreadMessages=2|notifications=5|isXyz=1|

 

Next Steps:

Andrey_Osadchuk
Level 10
July 7, 2020
Daniel, if you decide to try the method described above, review this article https://docs.adobe.com/content/help/en/analytics/technotes/low-traffic.html that explains the "side effect" in case of a high volume of unique values captured with that method