LeadBooster Browser API - Issues with tracking events

Hi Everyone!

I’m testing the code to send Leadbooster chat events to GA via GTM. When I’m testing in incognito mode, the 1st time i open the site i can see the following logs:

[warn] LeadBooster already exists
[console.log] LeadBooster tracking already initialized
[console.log] Event sent to GA: chat_greeting_shown

After that even If I manually open/close the chat widget it doesn’t get registered - I see no related console.logs to those Leadbooster chat events.

But If I then do a soft page refresh - it magically starts to work, the logs are:
[console.log] Initializing LeadBooster tracking
[console.log] LeadBooster tracking already initialized
[console.log] Event sent to GA: chat_greeting_shown
manually triggering the chat to open
[console.log] Event sent to GA: chat_opened

Could anyone point me it the right direction here?

Thanks in advance!

Click here to see the code I'm using inside of <head> tag
<script>
window.pipedriveLeadboosterConfig = {
    base: 'leadbooster-chat.pipedrive.com',
    companyId: *HIDDEN*,
    playbookUuid: 'HIDDEN',
    version: 2
};
(function () {
    var w = window;
    if (w.LeadBooster) {
        console.warn('LeadBooster already exists');
    } else {
        w.LeadBooster = {
            q: [],
            on: function (n, h) {
                this.q.push({ t: 'o', n: n, h: h });
            },
            trigger: function (n) {
                this.q.push({ t: 't', n: n });
            }
        };
    }
})();
</script>

<!-- GA Event Logging -->
<script>
window.dataLayer = window.dataLayer || [];
function sendToGA(eventName, eventCategory, eventLabel) {
    try {
        gtag('event', eventName, {
            'send_to': 'HIDDEN',
            'event_category': eventCategory,
            'event_label': eventLabel
        });
        console.log('Event sent to GA:', eventName);
    } catch (error) {
        console.error('Error sending event to GA:', error);
    }
}

let isInitialized = false;

function initLeadBoosterTracking() {
    if (isInitialized) {
        console.log('LeadBooster tracking already initialized');
        return;
    }

    if (typeof LeadBooster !== 'undefined' && typeof LeadBooster.on === 'function') {
        console.log('Initializing LeadBooster tracking');

        LeadBooster.on('opened', function() {
            sendToGA('chat_opened', 'pipedrive_chat', 'initiated');
        });

        LeadBooster.on('greetingOpened', function() {
            sendToGA('chat_greeting_shown', 'pipedrive_chat', 'greeting_displayed');
        });

        LeadBooster.on('conversationEnded', function(data) {
            var eventLabel = data.qualified ? 'chat-lead' : 'conversation-ended';
            sendToGA('conversation_ended', 'pipedrive_chat', eventLabel);
        });

        LeadBooster.on('closed', function() {
            sendToGA('chat_closed', 'pipedrive_chat', 'closed');
        });

        isInitialized = true;
    } else {
        console.error('LeadBooster or its methods are not available');
    }
}

function checkAndInitialize() {
    if (typeof LeadBooster !== 'undefined') {
        initLeadBoosterTracking();
    } else {
        console.log('LeadBooster not yet available, will try again');
        setTimeout(checkAndInitialize, 100);
    }
}

checkAndInitialize();
window.addEventListener('load', checkAndInitialize);
</script>

<!-- LeadBooster Embed Script -->
<script src="https://leadbooster-chat.pipedrive.com/assets/loader.js" async></script>