When and how to use s.clearVars in Omniture?

为君一笑 提交于 2019-12-17 16:55:23

问题


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 what are the downside to clear all the variables? am I also going to clear built-in Omniture variables (e.g. Campaign ID)? Or what is the best way to clear all custom (evar, props and events - things I set) in DTM?

My Ajax application seems to be caching data from call to call. I am experiencing the following problem.

http://trackingfirst.com/omniture-ajax-cache-issues/

Keen to understand s.clearVars how to use it in DTM. Thanks.


回答1:


I'm not sure I can give a definitive answer about best way to go about it without being able to fully evaluate your DTM setup, but one thing you could try:

In the rule where you are ultimately making your s.t or s.tl calls, do the following:

In the Conditions section, under Rule condition, choose Data > Custom and click the "Add Criteria" button.

Then in code box, put in:

var s = _satellite.getToolsByType('sc')[0].getS();
s.clearVars();
return true;

Update: You commented the following:

Thank you for your answer. Unfortunately my rules are all direct call rules and there seems to be no "condition" option in DTM. I have added the above code under - "custom page code" - analytics tool settings - but interestingly "custom page code" don't get call for direct call rules. I am going to try running it via "javascript/3rd party tags" see what happens. Other ideas I could try? thanks

You are right, Direct Call rules only have one condition and that is the string passed in the _satellite.track('string') call. Honestly, I have no idea why Adobe does this. Maybe one day Adobe will expand it to allow you to setup other conditions for direct call rules, and basically just have that "string" condition relabeled to be the direct call rule identifier to specify which one to invoke. Basically, they should just treat it like the page load and event based rules, except you just invoke it with that "string". Incidentally, that's sort of how rules are already invoked internally, within the core code (even the page load and event based rules) so it wouldn't be that much of a stretch for Adobe to expand Direct Call rules.

Also, you are right, adding the code to the "custom page code" section in the tool settings won't work either. That chunk of code only gets executed on initial load of the DTM library. Speaking of setting things in that custom page code section.. there are other "bugs" you should be aware of, if you are setting other Omniture vars there. Long story short is DTM doesn't just create an s object on first load and then reference it later during rules; it creates a whole new s object when a rule is triggered. So, if you set anything within those tool config custom code boxes (e.g. manually setting linkTrackVars or more commonly, making use of s_doPlugins which is also conspicuously missing from being baked into DTM...) they will NOT get preserved for direct rule calls! (But, it does preserve it from direct call to direct call. I know.. confusing and inconsistent, right?)

So this leads up to a solution for you.. basically, you need to disable letting DTM trigger the s.t or s.tl call. Just keep the radio button in Adobe Anlytics section set to "disabled" and then set everything you need to set manually, within a code box in the Javascript / Third Party Tags section. Within there, you can put that code, then set any additional Omniture variables you need to set. If you need to reference Data Elements, you can use _satellite.getVar('element_name') to get them, instead of the %element_name% placeholder you'd use in the Adobe Analytics section. Then, end it with the s.t() or s.tl() call yourself. In other words.. treat it as a normal Omniture implementation, where the code just happens to be hosted in DTM, instead of making use of whatever DTM has built in.

Update: AppMeasurement 1.8.0

AppMeasurement Release Notes (scroll down to JavaScript 1.8.0)

Adobe introduced two events you can register callback functions to:

s.registerPreTrackCallback
s.registerPostTrackCallback

With this, you can register a callback function that triggers s.clearVars()

Example

s.registerPreTrackCallback(function() {
  s.clearVars();
});



回答2:


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.



来源:https://stackoverflow.com/questions/28048759/when-and-how-to-use-s-clearvars-in-omniture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!