Skip to content

$_SESSION that has been unset is saved back in magento with custom GTM (google tag manager) x GTM Weltpixel

I have some issue after add custom tag in GTM and setting configuration in magento by Weltpixel for GTM extension

so, i have custom tag for tracking event login, logout, banner click, brand click, etc in GTM for integration with Moengage.

all configuration is done and clear, can track these activity in GTM or Moengage, in my magento local site its can running perfectly, but different when deploy in staging site

actualy, for tracking these event i use $_SESSION

flow:

in observer set $_SESSION['userLogin'],
enter image description here

then in default.phtml I get $_SESSION['userLogin'] and unset($_SESSION['userLogin'])
enter image description here

in layout, i add this code for default magento template
enter image description here

I checked, the result is:
when the .phtml track before the unset($_SESSION['userLogin']) has a session,
that’s right after the unset($_SESSION['userLogin']) there is no session,

session history before unset with var_dump in console.log

array(11) {
  // other session
  ["userLogin"]=>
  &array(2) {
    array(2) {
      ["unique_id"]=>
      string(26) "[email protected]"
      ["name"]=>
      string(10) "name example"
    }
  }
}

session history after unset

array(11) {
  // other session
}

its true, right ?

but,
when the page is reloaded again
in the .phtml track before unset($_SESSION['userLogin']) even there is a session again,
that’s right after unset($_SESSION['userLogin']) there is no session anymore

and so on, sometimes the $_SESSION['userLogin'] also disappears on its own

GTM result, double track (example if use event logout)

enter image description here

when checked in the observer section using logger, maybe there is a process 2 times setting $_SESSION['userLogin']

but, apparently not, only 1 time

enter image description here

why can it happen like that ?
Can someone help me ? thank you