Last active
August 29, 2015 14:13
-
-
Save tsega/1251316397d9b143bd4b to your computer and use it in GitHub Desktop.
Meteor Sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Router.onBeforeAction(function(){ | |
var postSlug = this.params.slug; | |
var currentPost = Posts.findOne({slug: postSlug}); | |
var anonymousSession = "anonymousViewers_"+currentPost._id; | |
var anonymousCount = Session.get(anonymousSession); | |
if(anonymousCount){ | |
Session.set(anonymousSession, parseInt(anonymousCount) + 1); | |
}else{ | |
Session.set(anonymousSession, 1); | |
} | |
this.next(); | |
}, { | |
only: ["post"] | |
}); |
garrilla
commented
Jan 21, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment