CleverTap session extender

Protects against irritating and dangerously short session inactivity timeouts, which can lead to losing progress when editing campaigns.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         CleverTap session extender
// @version      1.0
// @description  Protects against irritating and dangerously short session inactivity timeouts, which can lead to losing progress when editing campaigns.
// @author       Christopher Orr <chris@website>
// @website      https://klima.com/
// @namespace    https://klima.com/
// @license      MIT
// @match        https://*.dashboard.clevertap.com/*
// @icon         https://www.google.com/s2/favicons?sz=128&domain=clevertap.com
// @run-at       document-idle
// @grant        GM_xmlhttpRequest
// @connect      self
// ==/UserScript==

(function() {
    'use strict';

    const cleverTapRefresh = () => {
        console.log('UserScript: Keeping CleverTap session alive in the background…');

        // Fetch the top-level URL every 5–10 minutes, i.e. much more often than the ~45-minute session inactivity timeout.
        // This redirects to the main dashboard page, and so should prolong the current logged-in session
        GM_xmlhttpRequest({ url: '/' });

        // Repeat so long as this tab is open
        const intervalMs = 5 * 60 * 1000;
        return setTimeout(cleverTapRefresh, intervalMs + (intervalMs * Math.random()));
    };

    cleverTapRefresh();
})();