SOLVED

Trouble expiring _mkto_trk cookie

Go to solution
Matt_Stone2
Level 9

Trouble expiring _mkto_trk cookie

I'm attempting to expire the Marketo tracking cookie (_mkto_trk) with javascript in order to detach a user's history prior to submitting a kiosk form. This is the code I have set:

<script type="text/javascript">

function deleteCookie() {

var c_name = "_mkto_trk";

var expireDate = new Date();
expireDate.setDate(expireDate.getDate() - 1);
expireDate = expireDate.toGMTString()

document.cookie = c_name + "=deleted; expires=" + expireDate;

}

</script>


And this code fires onload with an image. I've verified this code does indeed work for test cookies I create, but for whatever reason, I can't seem to alter the Marketo cookie.

Additionally, I have used this code on both my www site and the Marketo subdomain, in case it was a domain issue, but neither seem to work.

Any ideas?
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Trouble expiring _mkto_trk cookie

I am not sure what the error is here. Here is a code sample where I was trying to solve a similar problem. 

https://gist.github.com/MurtzaM/2280e05690c23e18f325

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Re: Trouble expiring _mkto_trk cookie

I am not sure what the error is here. Here is a code sample where I was trying to solve a similar problem. 

https://gist.github.com/MurtzaM/2280e05690c23e18f325

Matt_Stone2
Level 9

Re: Trouble expiring _mkto_trk cookie

Thanks, Murtza. That worked.

I used a slightly different version that doesn't rely on the form submission, in case anyone else wants to do the same:

<script>
function delete_cookie( name, path, domain ) {
document.cookie = name + "=" +
((path) ? ";path="+path:"")+
((domain)?";domain="+domain:"") +
";expires=Thu, 01 Jan 1970 00:00:01 GMT";
}
 
function deleteMarketoCookie() {
delete_cookie( '_mkto_trk', '/', '.YOUR-DOMAIN.com');
}
</script>


<img src="someImageThatWillLoad.png" style="width: 1px; height: 1px" onload="deleteMarketoCookie();">
Anonymous
Not applicable

Re: Trouble expiring _mkto_trk cookie

I am glad you got it working! For future viewers of this thread, I created a blog post on the Marketo dev blog to document this:

http://developers.marketo.com/blog/delete-marketo-tracking-cookie/