s.getPreviousValue plugin not working

℡╲_俬逩灬. 提交于 2020-01-15 11:52:54

问题


On Page A, I have a s.tl() call on click of "Link A" where I am filling evar1 and triggering off an event1. This link A leads to Page B

Code on link click in page A

$(document).on('click','.nav.navbar-nav.subnav-breadcrumb a',function(){
    if($(this).text().toLowerCase().indexOf('create group')!=-1){
        s.events = "event1";
        s.linkTrackEvents = "event1";
        s.eVar1 = "Step 1";
        s.linkTrackVars = "eVar1,events";
        s.tl(true,'o','Step 1');    
    }
});

On pageload of Page B, in the do Plugins sections, I try to get the value of eVar set in the prev s.tl() call by the following code

function s_doPlugins(s) {
    console.log(s.getPreviousValue(s.eVar1,'cookie_name','event1') 
}

However, I get the value as 'undefined'. Does getPreviousValue() plugin not work on previous s.tl() calls? What am I doing wrong here?


回答1:


As mentioned in the documentation, since you are using the 3rd argument of s.getPreviousValue(), it will only store and trigger if the specified event is set (in both your case and doc example, that is event1).

Since you are setting event in the link click, s.getPreviousValue() triggers because s_doPlugins gets called on all s.t() and s.tl() calls, so at that point you should see the value in your cookie_name cookie (look in s_pers cookie if you are using combined cookie plugin).

However, on the next page (Page B) event1 isn't set, so when s_doPlugins gets called for the on-page s.t() call, s.getPreviousValue() will not update/return previous value.

In other words, when you specify an event in the 3rd argument, the plugin only triggers when the specified event is present in s.events. Basically first thing it does is check if 3rd arg exists then go through s.events and see if it's in there. If it's not, that's it, function ends with no return value (and that's why you get undefined returned).

I'm not sure what you're actually trying to accomplish but in my experience there aren't many use cases for specifying an event in the 3rd argument.



来源:https://stackoverflow.com/questions/29094075/s-getpreviousvalue-plugin-not-working

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