From ff84778d9bb224d4153be195c09dd82352d3a24b Mon Sep 17 00:00:00 2001 From: Alexis Georges Date: Mon, 22 Aug 2016 11:33:55 -0700 Subject: [PATCH] use truthy check and only register history listeners if there are goals --- src/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 37580dbf..72b8f4d6 100644 --- a/src/index.js +++ b/src/index.js @@ -260,7 +260,7 @@ function initialize(env, user, options) { }); function refreshGoalTracker() { - if (goalTracker !== null) { + if (goalTracker) { goalTracker.dispose(); } if (goals && goals.length) { @@ -268,13 +268,14 @@ function initialize(env, user, options) { } } - if (!!(window.history && history.pushState)) { - window.addEventListener('popstate', refreshGoalTracker); - } else { - window.addEventListener('hashchange', refreshGoalTracker); + if (goals && goals.length > 0) { + if (!!(window.history && history.pushState)) { + window.addEventListener('popstate', refreshGoalTracker); + } else { + window.addEventListener('hashchange', refreshGoalTracker); + } } - window.addEventListener('message', handleMessage); return client;