diff --git a/README.md b/README.md index 6d5843f4..72725eba 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,7 @@ ahoy.configure({ headers: {}, visitParams: {}, withCredentials: false, + keepAlive: false, visitDuration: 4 * 60, // 4 hours visitorDuration: 2 * 365 * 24 * 60 // 2 years }); @@ -197,6 +198,12 @@ When `trackVisits` is set to `false`, Ahoy.js will not attempt to create a visit on the server, but assumes that the server itself will return visit and visitor cookies. +To keep cookies alive set: + +```javascript +ahoy.configure({ keepAlive: true }); +``` + ### Subdomains To track visits across multiple subdomains, use: diff --git a/src/index.js b/src/index.js index 3915edd4..2bb46e6d 100644 --- a/src/index.js +++ b/src/index.js @@ -14,6 +14,7 @@ const config = { headers: {}, visitParams: {}, withCredentials: false, + keepAlive: false, visitDuration: 4 * 60, // default 4 hours visitorDuration: 2 * 365 * 24 * 60 // default 2 years }; @@ -302,7 +303,9 @@ function createVisit() { log("Visit tracking disabled"); setReady(); } else if (visitId && visitorId && !track) { - // TODO keep visit alive? + if (config.keepAlive) { + setCookie("ahoy_visit", getCookie("ahoy_visit"), config.visitDuration); + } log("Active visit"); setReady(); } else {