From 62444b9a13aaa0441dc3716229786a0893147065 Mon Sep 17 00:00:00 2001 From: Kane York Date: Tue, 15 Sep 2015 12:25:12 -0700 Subject: [PATCH] Fix the visit tracking logic --- .../discourse/initializers/signup-cta.js.es6 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/initializers/signup-cta.js.es6 b/app/assets/javascripts/discourse/initializers/signup-cta.js.es6 index cc25f64cb8d..d83a6ecf5da 100644 --- a/app/assets/javascripts/discourse/initializers/signup-cta.js.es6 +++ b/app/assets/javascripts/discourse/initializers/signup-cta.js.es6 @@ -73,13 +73,17 @@ export default { // Record a visit const nowVisit = new Date().getTime(); - const lastVisit = keyValueStore.getInt('anon-last-visit', nowVisit); - if (nowVisit - lastVisit > ONE_DAY) { - // more than a day + const lastVisit = keyValueStore.getInt('anon-last-visit', 0); + if (!lastVisit) { + // First visit + keyValueStore.setItem('anon-visit-count', 1); + keyValueStore.setItem('anon-last-visit', nowVisit); + } else if (nowVisit - lastVisit > ONE_DAY) { + // More than a day const visitCount = keyValueStore.getInt('anon-visit-count', 1); keyValueStore.setItem('anon-visit-count', visitCount + 1); + keyValueStore.setItem('anon-last-visit', nowVisit); } - keyValueStore.setItem('anon-last-visit', nowVisit); checkSignupCtaRequirements(); }