Delete cookies on mautic after logout

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

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

On logout try clearing the following cookies:

image

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

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

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)

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.

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 domain is not possible when logging out on app.example.com.

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 (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 at the end of your logout process on 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 or something. But I would start with first suggestion as the second one is a bit odd.

The first suggestion would not work because as the docs mention the cookies set under 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?

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.

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.

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

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?

Hi joeyk, thanks for your reply.

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

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 :slight_smile:

I use a cookie delete plugin to remove the cookies.

you mean remove the third party cookies from mautic installation?

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.

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.

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.

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