From a142d664e701addfdf8eab1157c55a5bdb1f8c77 Mon Sep 17 00:00:00 2001 From: Denis Lukianov Date: Tue, 18 Jul 2023 15:07:35 +0300 Subject: [PATCH] add the ability to keep cookies alive --- README.md | 7 +++++++ src/index.js | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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 {