I want to find the time a user spend on an article page.
I have page which shows list of an articles , when you click any article from that page it will show you the content of that article.
For now i have the following code for the article route
@app.route("/post/<post_id>")
def post(post_id):
post = mongo.db.articles
sp = post.find_one({'_id': ObjectId(post_id)})
##################
userhistory = mongo.db.userhistory
history = {'id' :ObjectId(post_id),'title':sp['Heading'],'User':current_user.user_json['email'],'DateTime':datetime.now()}
userhistory.insert(history)
############################################
#sp = post.find_one({'_id':post_id})
return render_template('post.html', title=post.title, post=sp)
I want to calculate the time a user spends on that specific article and add it to MongoDB collection(user history). So when a user has finished reading the article and clicks back on the browser it should calculate the time spent.
Please Help