Search code examples
adobe-analytics

Set the Visitor ID in Adobe Analytics through DTM


I'm trying to set the Visitor ID in Adobe Analytics through DTM.

Above the s_code I have:

var visitor = new Visitor("xxxx") 
visitor.trackingServer = "xxx.xx.xx.omtrdc.net" 

I've created a data element where the legacy code used to call the

Visitor.getInstance("xxxx");

and set the Visitor ID to %Visitor ID%

That's not working however, and my visitor ID is always just set to %Visitor ID% and obviously not reading any values. I'd really appreciate any input that someone can give me.

Thanks, Mike


Solution

  • The Visitor ID pops s.visitorID and is in general related to visitor id, but is not the same as s.visitor which is what gets popped for the VisitorAPI integration. DTM does not currently have a built-in field for the s.visitor variable, so you will have to set it yourself within the config, either in the Library Management code editor (assuming you are opting to c/p the core lib and not the "Managed by Adobe" option) or else in the Custom Page Code section.

    Since you are popping it in a data layer first, you can reference the data layer like this:

    s.visitor = _satellite.getVar('Visitor ID');

    NOTE: A separate potential issue you may have is with whether or not the Visitor object is available for your data element. Since data elements are the first thing to be evaluated by DTM, you will need to ensure that the VisitorAPI.js library is output before your top page DTM script include.

    If this is a problem for you, or if you are wanting to host VisitorAPI.js within DTM, then you may need to adjust where you are popping that stuff. For example, place the VisitorAPI core code above the custom code as the first stuff within the data element, before:

    var visitor = new Visitor("xxxx") visitor.trackingServer = "xxx.xx.xx.omtrdc.net

    Or, don't use the data element at all. Instead, put the VisitorAPI code within the Adobe Analytics custom code or core lib section and pop all that stuff (aboove the s.visitor assignment). Or a number of other methods; point is, VisitorAPI stuff must be loaded before the data element can make use of it, same as it must be loaded before Adobe Analytics can make use of it.