is it possible to track ALL contextData when s.linkTrackVars? | Community
Skip to main content
New Participant
October 26, 2022
Solved

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

  • October 26, 2022
  • 3 replies
  • 938 views

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.

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_

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()

3 replies

Alexis_Cazes_
Alexis_Cazes_Accepted solution
New Participant
October 27, 2022

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()
Jennifer_Dungan
New Participant
October 27, 2022

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.

yuhuisg
New Participant
October 27, 2022

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

Jennifer_Dungan
New Participant
October 26, 2022

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?