Search code examples
javascriptadobe-analytics

Assigning an array of values in Adobe DTM to a list var


I have a list of values which I have gathered from some HTML elements in a page with some javascript. I have then stored these within an array called 'a'. This is all processed as a data element.

a = 123, 456, 789, 102

What I would like to achieve is to find all of the values on a given page then record an instance against each value as an instance, essentially I am counting the number of times an item appears in search results by ID. The part I am stuck on, is how I would assign these values to a list var and record these as an event.


Solution

  • By calling s.events, s.linkTrackVars and s.linkTrackEvents I was able to record the data within a list variable in omniture. I have provided the code I used below:

    if (location.href.indexOf('example.com') != '-1') {
        var a = "";
    
        $('div.info').each(function() {
              if(a.length<1){
                a =($(this).attr('id'))
              }else{
                 a = a + "," + ($(this).attr('id'))
              }
            })
            if (a.length > 1)
                s.list1 = a;
                    s.events="event100";
                    s.linkTrackVars="list1,events";
                    s.linkTrackEvents="event100";
                    s.tl(true, 'o', 'ID count');
        }