Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

User metadata "template" for digitalData

danielwalo
Level 2
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
AlexisCazes
Correct answer by
Community Advisor
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
AlexisCazes
Correct answer by
Community Advisor
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

Andrey_Osadchuk
Community Advisor
Community Advisor
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
danielwalo
Level 2
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.