When and how to use s.clearVars in Omniture?

前端 未结 2 1667
不思量自难忘°
不思量自难忘° 2020-12-06 23:29

I am trying to understand where in DTM can I use s.clearVars? do I place it under \"custom page code\" under Global config or under Rules \"custom page code\"?

Also

2条回答
  •  孤街浪徒
    2020-12-07 00:22

    I came up with a very simple solution for implementing clearVars which simply requires overriding s.t() to trigger clearVars after every call to it.

    You'll want to define this globally such as in global Custom Code in DTM, so that it only runs once:

    // override s.t() to trigger clearVars after every call to it
    var t_orig = s.t;
    s.t = function(){ 
      t_orig.apply(this, arguments);
      try {
        s.clearVars();
      } catch(e){}
    }
    

    With this solution, you never need to worry about accidentally clearing variables set by custom scripts or event-based rules.

    A second scenario is when you have multiple s.tl() calls in an application, and you'd like to clearVars() between one event and another to avoid sending the same variables in the next s.tl().

    For that, use the following code in your custom script just before you invoke the s.tl(), or in the top of the custom conditions block in an event-based DTM rule:

    // clear pre-existing variables here, before anything new gets set
    var s = _satellite.getToolsByType('sc')[0].getS(); // this line is optional and for use in DTM only; not necessary if you are sure your "s" object is already set to the correct reference.
    s.clearVars();
    

    UPDATE

    As @CrayonViolent mentioned, Adobe has introduced callback methods for just this purpose as of AM 1.8.0: s.registerPreTrackCallback and s.registerPostTrackCallback.

    I will leave my original answer here as an alternate approach, as there are still differences between using a built-in function and overriding one, and more fine-grained control of the timing of things could come in handy (for example if you want to guarantee that your code fires after any other registered callbacks.)

    Also the approach I outlined in the second scenario is still valid and is different than using s.registerPreTrackCallback, because you control the timing based on custom events.

提交回复
热议问题