# Mautic cookies: mtc\_id mautic\_session\_id mautic\_session\_name

**URL:** <https://forum.mautic.org/t/mautic-cookies-mtc-id-mautic-session-id-mautic-session-name/8136>\
**Category:** Product Support\
**Created:** [April 8, 2017, 7:40am UTC](https://forum.mautic.org/t/mautic-cookies-mtc-id-mautic-session-id-mautic-session-name/8136 "2017-04-08T07:40:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.mautic.org/u/saint)\
**Post date:** [April 8, 2017, 7:40am UTC](https://forum.mautic.org/t/mautic-cookies-mtc-id-mautic-session-id-mautic-session-name/8136/1 "2017-04-08T07:40:14Z")

</div>

hi folks,  
  
  
  
I’m trying to understand cookie behavior in mautic and at first sight it wasn’t obvious. I understand there are a few cookies, namely:  
  
  
  
mtc\_id: id of the user  
  
mautic\_session\_id: session id, and there is another cookie with this id that points to the user id  
  
mautic\_session\_name: I don’t know what this is used for  
  
  
  
The problem is that mtc\_id seems to be sometimes set and sometimes not (at least in my case, I have a suspicion using https for the tracking js is making things a bit more challenging).  
  
  
  
**Question is:** how can I get the id of the user (reliably) without an API call, just using cookies assuming CORS and cookie domain settings are fine. Shall I do an OR with $\_COOKIE[“mtc\_id”] or $\_COOKIE[$\_COOKIE[“mautic\_session\_id”]]?  
  
  
  
–  
  
  
  
Below is my search on the topic if anyone ends up here from a search.  
  
  
  
There is a very old thread at: [https://www.mautic.org/community/index.php/82-how-can-i-use-the-mautic-api/0#p536](https://www.mautic.org/community/index.php/82-how-can-i-use-the-mautic-api/0#p536) on the topic but it’s so old I can’t rely on it.  
  
  
  
Also  
  
  
  
[https://developer.mautic.org/#manipulating-contacts-(leads)](https://developer.mautic.org/#manipulating-contacts-(leads))  
  
  
  
has some php code

\<?php  
// Currently tracked lead based on cookies  
$leadModel = $this-\>getModel('lead');  
$lead = $leadModel-\>getCurrentLead();  
$leadId = $lead-\>getId();  
  
Which I'm not sure about because I can't figure out what it does.  
  
Any suggestions?

---

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.mautic.org/u/saint)\
**Post date:** [April 8, 2017, 7:40am UTC](https://forum.mautic.org/t/mautic-cookies-mtc-id-mautic-session-id-mautic-session-name/8136/2 "2017-04-08T07:40:14Z")

</div>

hi folks,

I’m trying to understand cookie behavior in mautic and at first sight it wasn’t obvious. I understand there are a few cookies, namely:

mtc\_id: id of the user  
mautic\_session\_id: session id, and there is another cookie with this id that points to the user id  
mautic\_session\_name: I don’t know what this is used for

The problem is that mtc\_id seems to be sometimes set and sometimes not (at least in my case, I have a suspicion using https for the tracking js is making things a bit more challenging).

Question is: how can I get the id of the user (reliably) without an API call, just using cookies assuming CORS and cookie domain settings are fine. Shall I do an OR with $\_COOKIE[“mtc\_id”] or $\_COOKIE[$\_COOKIE[“mautic\_session\_id”]]?

–

Below is my search on the topic if anyone ends up here from a search.

There is a very old thread at: [https://www.mautic.org/community/index.php/82-how-can-i-use-the-mautic-api/0#p536](https://www.mautic.org/community/index.php/82-how-can-i-use-the-mautic-api/0#p536) on the topic but it’s so old I can’t rely on it.

Also

[https://developer.mautic.org/#manipulating-contacts-(leads)](https://developer.mautic.org/#manipulating-contacts-(leads))

has some php code

\<?php // Currently tracked lead based on cookies $leadModel = $this-\>getModel('lead'); $lead = $leadModel-\>getCurrentLead(); $leadId = $lead-\>getId(); Which I'm not sure about because I can't figure out what it does. Any suggestions?

---

<div class="post-metadata">

**Author:** ![isleshocky77](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/isleshocky77/32/8316_2.png) [@isleshocky77](https://forum.mautic.org/u/isleshocky77)\
**Post date:** [October 5, 2017, 8:11pm UTC](https://forum.mautic.org/t/mautic-cookies-mtc-id-mautic-session-id-mautic-session-name/8136/3 "2017-10-05T20:11:00Z")

</div>

Are you working on a local installation? I also for the past year have been finding the mtc\_id to be extremely unreliable; however, it’s mostly while working on my local installation.

I just tracked down what looks like a change a year ago:  
[https://github.com/mautic/mautic/commit/90b64034d09510d6f77fb9e790e91938bbadec9b#diff-680a217018ae349738fa38e34b7a19f8R152](https://github.com/mautic/mautic/commit/90b64034d09510d6f77fb9e790e91938bbadec9b#diff-680a217018ae349738fa38e34b7a19f8R152)

Where 127.0.0.1 is always added to do not track. This means you’ll get a mautic\_session\_id, but not a mtc\_id.

Later on it was added so this functionality only happens in production:  
[https://github.com/mautic/mautic/commit/78a64d35677b9c19fcbeacf3f1d4879e4522a208](https://github.com/mautic/mautic/commit/78a64d35677b9c19fcbeacf3f1d4879e4522a208)

However, I didn’t realized this so I never thought to put my dev url into my local website tracker  
i.e. instead of tracking [https://mautic.example.org/mtc.js](https://mautic.example.org/mtc.js) use [https://mautic.example.org/index\_dev.php/mtc.js](https://mautic.example.org/index_dev.php/mtc.js)

That was my issue at least.
