Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

When to use clearVars


Level 3

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 > call s.clearVars()


#3 CMS Application 

s.eVar100="some variable;,"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 or is it custom?, based on use cases, like, it can be used either before or after? 

2 Replies


Community Advisor

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.


Employee Advisor

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