Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!
SOLVED

is it possible to track ALL contextData when s.linkTrackVars?

Avatar

Level 4

Is it possible to track ALL contextData that I am setting like a wild card (i.e. s.contextData.*)? I'm having to add it to a data element which tracks all variables and adding each individual contextData to track.

1 Accepted Solution

Avatar

Correct answer by
Level 10

use this code to achieve what you need

 

function addAllContextDataToLinkTrackVars() {
    s.linkTrackVars = resetContextDataFromLinkTrackVars()
    if (s.contextData) {
        let keys = Object.keys(s.contextData)
        keys.forEach(key => {
            s.linkTrackVars = s.linkTrackVars ? `${s.linkTrackVars},contextData.${key}` : `contextData.${key}`
        })
    }
}

function resetContextDataFromLinkTrackVars() {
    let arrayLinkTrackVars = s.linkTrackVars.split(',')
    if (arrayLinkTrackVars.length > 0) {
        arrayLinkTrackVars = arrayLinkTrackVars.filter(item => !item.includes('contextData.'))
    }
    return arrayLinkTrackVars.toString()
}

//then call 
addAllContextDataToLinkTrackVars()

View solution in original post

4 Replies

Avatar

Community Advisor and Adobe Champion

I assume you are talking about in Adobe Launch?

 

So you are setting your eVars and props in "Set Variables", but you are also setting context variables and those are not being included correct?

Avatar

Community Advisor

I don't think Adobe allows for wildcards with context data, not even with Analytics' Processing Rules.

Avatar

Correct answer by
Level 10

use this code to achieve what you need

 

function addAllContextDataToLinkTrackVars() {
    s.linkTrackVars = resetContextDataFromLinkTrackVars()
    if (s.contextData) {
        let keys = Object.keys(s.contextData)
        keys.forEach(key => {
            s.linkTrackVars = s.linkTrackVars ? `${s.linkTrackVars},contextData.${key}` : `contextData.${key}`
        })
    }
}

function resetContextDataFromLinkTrackVars() {
    let arrayLinkTrackVars = s.linkTrackVars.split(',')
    if (arrayLinkTrackVars.length > 0) {
        arrayLinkTrackVars = arrayLinkTrackVars.filter(item => !item.includes('contextData.'))
    }
    return arrayLinkTrackVars.toString()
}

//then call 
addAllContextDataToLinkTrackVars()

Avatar

Community Advisor and Adobe Champion

Yes, I just hope that when this code is called, s.linkTrackVars has already been populated with what has been defined in the Set Variables step... 

 

You need to make sure that s.linkTrackVars contains all the elements you want tracked... you don't want to overwrite with context vars (but this at least is grabbing the existing values then passing them back in), but you also need to make sure that this was already set, otherwise Adobe's set Variables may overwrite this and the context variables could be lost. 

 

I do however believe that adding this into the Custom Code of the Set Variables rule will be the correct location, and looping through each key in the context data makes this very dynamic.