Suggestions for JS 'reload problem': time measurement, click count and mousehover

52 views
Skip to first unread message

Nikki Maier

unread,
Jun 14, 2021, 10:50:36 AM6/14/21
to oTree help & discussion
Hey all,

I am programming my first otree single player experiment. I want to measure the time between two button clicks, the number of clicks and maybe the mouseenter/ mouseleave for div elements. The time between two button clicks and the clickcount are important variables of interest.

I have used JavaScript to measure the time between two button clicks and the number of clicks. As recommended I have stored the data using a hidden input field and it works fine. However, one problem is that the data gets lost, when the page is reloaded. Because the time measurement is an important variable, I am afraid that the data gets biased due to the reload problem.

From your experience, would you recommend another way to store the data (not the hidden input field)? I have read about live pages. Have you got any experience with the reload problem?

Many thanks!



Chris @ oTree

unread,
Jun 14, 2021, 11:32:46 AM6/14/21
to oTree help & discussion
Yes if you use live pages, then you can avoid issues due to reloading the page. 

another approach is to record whether the page was reloaded or not (you can measure this by incrementing a player field in vars_for_template), and discard the ones that were reloaded:

num_page_loads = models.IntegerField(                                 
    initial=0,                                                        
    doc="""If more than 1, indicates that the user reloaded the page. 
    This complicates the interpretation of the timestamps.""",       
)             

@staticmethod                         
def vars_for_template(player: Player):
    player.num_page_loads += 1        
                                                                                              

Reply all
Reply to author
Forward
0 new messages