# Delete cookies on mautic after logout

**URL:** <https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505>\
**Category:** General Discussion\
**Tags:** community, development\
**Created:** [December 21, 2020, 6:03pm UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505 "2020-12-21T18:03:15Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![namratasaun](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/namratasaun/32/2801_2.png) [@namratasaun](https://forum.mautic.org/u/namratasaun)\
**Post date:** [December 21, 2020, 6:03pm UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/1 "2020-12-21T18:03:15Z")

</div>

I am using Mautic with my website where I have a login and logout functionality. I want to clear all the cookies after logout so that when next user comes, it stops tracking the previous user and create a new one

---

<div class="post-metadata">

**Author:** ![guentr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/guentr/32/1045_2.png) [@guentr](https://forum.mautic.org/u/guentr)\
**Post date:** [October 8, 2021, 2:23pm UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/2 "2021-10-08T14:23:53Z")

</div>

Hi @namratasaun, have you found a solution for this?

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [October 8, 2021, 4:01pm UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/3 "2021-10-08T16:01:15Z")

</div>

On logout try clearing the following cookies:

![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/f/f3710a6ca766c95aa4ffda9e63f5b67291dde04e.png)

If it does not work, report your findings and we can investigate it further.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [October 9, 2021, 8:53am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/4 "2021-10-09T08:53:24Z")

</div>

He wants to do it programatically. The same pc is used by many people.

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [October 9, 2021, 12:36pm UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/5 "2021-10-09T12:36:00Z")

</div>

How to do this programmatically depends highly on which system is used for login & logout function. But the general idea is the same - you have to delete the old cookies before Mautic tracking script is fired when new user logs in.

The following three lines should delete cookies in PHP (this should be called during logout process)

```auto
setcookie('mautic_device_id', '', -1, '/', 'example.com', true, false);
setcookie('mtc_id', '', -1, '/', 'example.com', true, false);
setcookie('mtc_sid', '', -1, '/', 'example.com', true, false);

```

Without testing how this behaves in practice I cannot say if this works or not. However I am interested in solving this if @namratasaun you do not have the technical know-how I would be interested to look this into more detail for you.

---

<div class="post-metadata">

**Author:** ![guentr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/guentr/32/1045_2.png) [@guentr](https://forum.mautic.org/u/guentr)\
**Post date:** [October 13, 2021, 10:14am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/6 "2021-10-13T10:14:34Z")

</div>

I am not sure if this approach is helpful in my case. When running my website under **app**.example.com and loading the tracker from **mautic**.example.com, deleting cookies from the [mautic.example.com](http://mautic.example.com) domain is not possible when logging out on [app.example.com](http://app.example.com).

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [October 14, 2021, 3:26pm UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/7 "2021-10-14T15:26:49Z")

</div>

I would have to test it to be sure, but as far as I know mautic sets cookies via client side (JS). for the domain you are tracking not the domain Mautic is cumming from. If you look into Mautic cookies in your browser you should see they are set on [app.example.com](http://app.example.com) (it depends how you Mautic tracking script is set).

Lastly, even if what I said is not true, you should still be able to achive this, by redirecting to [mautic.example.com/clear.php](http://mautic.example.com/clear.php) at the end of your logout process on [app.example.com](http://app.example.com).

In clear.php you say that you want to delete all mautic cookies and then redirect back to [app.example.com/login](http://app.example.com/login) or something. But I would start with first suggestion as the second one is a bit odd.

---

<div class="post-metadata">

**Author:** ![guentr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/guentr/32/1045_2.png) [@guentr](https://forum.mautic.org/u/guentr)\
**Post date:** [October 18, 2021, 8:32am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/8 "2021-10-18T08:32:55Z")

</div>

The first suggestion would not work because [as the docs mention](https://docs.mautic.org/en/contacts/manage-contacts/contact-monitoring#local-contact-cookie-first-party-cookie) the cookies set under [app.example.com](http://app.example.com) are not used for tracking, but can be used for accessing the contact id and integrate with the API further.  
The second suggestion would involve some custom implementation on Mautic, right @mzagmajster?

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [October 18, 2021, 12:13pm UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/9 "2021-10-18T12:13:53Z")

</div>

Yes, on Mautic side you need a script to clear cookies, I think the easiest approach is to start with simple php script that clears Mautic cookies and redirect back to [app.example.com](http://app.example.com).

If it turns out that in practice this does not work, I would try to do the same by actually writing custom plugin and deleting tracking info via Mautic core functions.

---

<div class="post-metadata">

**Author:** ![francesco](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/francesco/32/82_2.png) [@francesco](https://forum.mautic.org/u/francesco)\
**Post date:** [January 4, 2023, 9:10am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/10 "2023-01-04T09:10:20Z")

</div>

Hello, someone find a solution to solve this issue?

I have the same problem, i have an active integration via API that updates mautic’s data with website’s account data.

via tracking script I add tags based on the website the user is subscribed to and the category of the articles the user reads while browsing my websites.

when USER A disconnects from website and USER B log in mautic still tracks USER B pages into USER A contact

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 5, 2023, 7:39am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/11 "2023-01-05T07:39:08Z")

</div>

If you are an Mautic admin in a browser, you should not be tracked at all. You are a ghost for the system.  
Is this what you want to stop?

---

<div class="post-metadata">

**Author:** ![francesco](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/francesco/32/82_2.png) [@francesco](https://forum.mautic.org/u/francesco)\
**Post date:** [January 5, 2023, 7:54am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/12 "2023-01-05T07:54:11Z")

</div>

Hi joeyk, thanks for your reply.

No I’m testing websites from Firefox and I’m using chrome as admin for Mautic.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 5, 2023, 7:56am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/13 "2023-01-05T07:56:32Z")

</div>

> when USER A disconnects from website and USER B log in mautic still tracks USER B pages into USER A contact

This is how Mautic’s return visitor function should work via the tracking script. Regular users shouldn’t use the same computer, just you 🙂

I use a cookie delete plugin to remove the cookies.

---

<div class="post-metadata">

**Author:** ![francesco](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/francesco/32/82_2.png) [@francesco](https://forum.mautic.org/u/francesco)\
**Post date:** [January 5, 2023, 7:58am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/14 "2023-01-05T07:58:56Z")

</div>

you mean remove the third party cookies from mautic installation?

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 5, 2023, 8:01am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/15 "2023-01-05T08:01:06Z")

</div>

No I mean, if I want to test, I remove the Mautic cookie from my test browser (FF in your case) manually to test what user B would see.

---

<div class="post-metadata">

**Author:** ![francesco](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/francesco/32/82_2.png) [@francesco](https://forum.mautic.org/u/francesco)\
**Post date:** [January 5, 2023, 8:08am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/16 "2023-01-05T08:08:17Z")

</div>

I have done it via php (i’m using a custom cms that i wrote by myself and i added the php code to remove mautic cookies on logout) but when user B log into the system mautic still tracks the USER A that logged out.

at the moment i’m leaving this issue unresolved (i don’t really know how many users uses public computers) and, because of I’m not using mautic form to sign up users, i’m tryng to find a way to merge contacts created via api (on sign up) with anonymous contact created by tracking script.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 5, 2023, 9:55am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/17 "2023-01-05T09:55:50Z")

</div>

If you want to edit an anon contact to be known by adding email, the best way is to read out the mtc.id from the cookie and update the contact based on that id with the email address.

---

<div class="post-metadata">

**Author:** ![francesco](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/francesco/32/82_2.png) [@francesco](https://forum.mautic.org/u/francesco)\
**Post date:** [January 5, 2023, 10:11am UTC](https://forum.mautic.org/t/delete-cookies-on-mautic-after-logout/17505/18 "2023-01-05T10:11:10Z")

</div>

The code i wrote is this:

i place tracking code only for logged in users and only in registration page for logged out users. I made this choice because i had over 1.200.000 anonymous contacts into mautic with tracking code placed in all pages.

I have 3 cases:  
**User still not registered** : i set tracking script into registration page so i can read the mautic cookie, then the user fill the form and then i call my custom method updateMauticData that read mtc\_id cookie and updates the lead with name email etcetera

**Users already registered and logged already sent to mautic via API** : in this case i have the issue with mautic\_id in database different from mtc\_id cookie value. Here i must update the mautic\_id database value with mct\_id and then i saw that mautic will merge the 2 contacts giving me the id of the one i created with API so i have to update again the database mautic\_id value with the original one

Users already registered and logged but not sent to mautic via API: in this case i must only edit them via API using mtc\_id as id
