Expand my Community achievements bar.

Join us at Adobe Summit 2024 for the Coffee Break Q&A Live series, a unique opportunity to network with and learn from expert users, the Adobe product team, and Adobe partners in a small group, 30 minute AMA conversations.
SOLVED

User metadata "template" for digitalData

Avatar

Level 2

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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:

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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:

Avatar

Level 10
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

Avatar

Level 2
Thanks for this great solution and for the notes on low traffic filtering. I think this is going to work for us because we won't have that many unique values to contend with.