When to use clearVars | Community
Skip to main content
Level 4
Oct 5, 2020 6:38 PM UTC
Solved

When to use clearVars

Hi all,

 

I feel like this is a tricky question, should s.clearVars(); be used before or after? Couple of use cases I have encountered, 

 

#1 In Launch, 

Clear Variables > Set Variables > Send Beacon

 

#2 Using AMO.js 

Track events and eVars > fire s.tl() > call s.clearVars()

 

#3 CMS Application 

s.linkTrackVars="events,eVar100";
s.linkTrackEvents="events,event200";
s.events="event200";
s.eVar100="some variable;
s.tl(this,"o",null);

In this case I was questioning when to fire s.clearVars()? Because i'm running into an issue where the event200 is getting picked by AMO.js and the same event is getting fired twice on separate occasions. 

 

Is there a general rule which says fire s.clearVars() before tracking or after s.tl()? or is it custom?, based on use cases, like, it can be used either before or after? 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
yuhuisg
yuhuisgAccepted solution
New Participant
Oct 6, 2020 9:50 AM UTC

You determine when you want to use s.clearVars(). There's no hard-and-fast rule. It's simply a convenient way to "wipe the slate clean" before the next tracking call.

2 replies

khurshid
Employee
Oct 6, 2020 7:50 PM UTC

It specially help in SPAs where you want to clean all the variables before sending a new server call. 

Translate
yuhuisg
yuhuisgAccepted solution
New Participant
Oct 6, 2020 9:50 AM UTC

You determine when you want to use s.clearVars(). There's no hard-and-fast rule. It's simply a convenient way to "wipe the slate clean" before the next tracking call.

Translate