Search code examples
adobeanalyticsadobe-analytics

Adobe DTM to set query string in eVar and sProp


So normally I would use the s.getQueryParam(); to parse out my URLs for query strings that I've been using.

s.eVar8=s.getQueryParam('cid,pid,eid',':');
s.prop28=s.getQueryParam('Role');

But since DTM has that all built into it, how would you really define that? I know I can set a page load rule using the campaign variable, but what if I have multiple parameters separated by ":"

www.domain.com?cid=blah1:blah2:blah3&pid=blah4:blah5:blah6&eid=blah7:blah8:blah9

Is there something that I'm missing when using this approach? Should I be capture these values into a data element then passing the data element into a page load rule using an eVar or sProp?


Solution

  • For variables that only look for a single URL parameter:

    Create a Data Element of Type URL Parameter. For Parameter Name, put e.g. "Role" (no quotes) for prop28. Alternatively, you can do the same thing below, for multiple.

    For variables that look for multiple URL parameters:

    Create a Data Element of Type Custom Script. Click the [Open Editor] button and in the code box, add the following:

    var d=':',
        p=['cid','pid','eid'],
        v=[],c,l,q;
    for (c=0,l=p.length;c<l;c++) {
      q=_satellite.getQueryParamCaseInsensitive(p[c]);
      if (q) v.push(q);
    }
    return v.join(d);
    

    The d= and p= values are based on what you have for eVar8. This isn't 100% the same as AA's s.getQueryParam plugin but it's most of it; the parts you care about based on your posted code.

    Reference the Data Element(s)

    In the Adobe Analytics tool config, in the Global Variables section, you can add your prop(s) and eVar(s) there, using %data_element_name_here% syntax.