Zend certified PHP/Magento developer

How to fix Magento’s built-in session management that conflict with how GTM handles sessions causing session regeneration issue

Anyone have this issue before, I notices even in a freshly installed magento 2.4.4p4 commerce edition this issue occur

Let me know if this is the correct page to post this issue or I should post this issue into a magento github community or Google Analytics community,

The issue can be replicated by installing fresh magento 2.4.4p4 commerce edition, added the GTM script as below onto a custom head script

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->

Install Google Chrome GA4 Debugger Extension, navigate through magento system and analyse on the changes happening on the Session ID part

Refer below screenshot on how I track the changes in session ID

_ga_XXXXX refers to my GA session ID_ga_XXXXX refers to my GA session ID
notice the session ID here original is 1713951199notice the session ID here original is 1713951199
now notice that the session ID change to 1713950221now notice that the session ID change to 1713950221