Re: Overwrite Munckin Cookie

Nainsikala_123
Level 1

Overwrite Munckin Cookie

I am trying to overwrite _mtko_trk cookie and it is updating fine without page reload .But the issue is , in visitwebpage Activity , cookie that is passing  is the previous one.

 

 

What's wrong that I have done ?

 

7 REPLIES 7
SanfordWhiteman
Level 10 - Community Moderator

Re: Overwrite Munckin Cookie

Well, first, it's _mkto_trk, not _mtko_trk.

 

But we couldn't know what you're doing wrong without having a look at your code.

Nainsikala_123
Level 1

Re: Overwrite Munckin Cookie

I have 2 instances based on user type but in prelogin I have set one cookie on 1 instance.

Once user is logged in, based on user type cookie is updated with instance 2.

 

So the issue is , when visitwebpage triggers, the request payload has instance 1 cookie.

 

_mchNc: 1602491155940
_mchRu: some value
_mchId: instance1
_mchTk: instance1 cookie token
_mchHo: hostname
_mchPo: some value
_mchPc: some value
_mchVr: some value
_mchEcid:
_mchRe: hostname

 

So why these values are not updating as per new cookie ?

 

One more question here, when does these values gets initiated ?

SanfordWhiteman
Level 10 - Community Moderator

Re: Overwrite Munckin Cookie

Again, I need to see the code you're attempting to use to do this. You haven't provided enough information.

Nainsikala_123
Level 1

Re: Overwrite Munckin Cookie

This is the piece of code, which is invoking to create cookie.

 

(function() {
var didInit = false;
function initMunchkin() {
if(didInit === false) {
didInit = true;
Munchkin.init(munckinID)
var existingCookie = getCookieValue('_mkto_trk')
if( existingCookie && existingCookie.indexOf(munckinID)===-1) {
var days = 730
var date = new Date();
add_years(date, 2).toString()
var dataarr = getMarketoCookieValue(munckinID, 2)
if(dataarr.length>0) {
document.cookie = "_mkto_trk=" + dataarr[0] + "; Max-Age= "+date.toJSON()+";domain="+dataarr[1];
}
}
}
}
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src='//munchkin.marketo.net/munchkin.js';
s.onreadystatechange = function() {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
initMunchkin();
}
};
s.onload = initMunchkin;
document.getElementsByTagName('head')[0].appendChild(s);
})();
SanfordWhiteman
Level 10 - Community Moderator

Re: Overwrite Munckin Cookie

That's clearly not all your code, since it's calling multiple userland functions that aren't defined here.

 

Also don't understand what you're trying to do with the max-age; you shouldn't be passing a stringified Date to max-age, which officially accepts only a Number. (There's a distracting typo in munckinID, too.)

 

Overall, although I don't have the code you're really running, the timing seems wrong. What is the actual business purpose of manually recreating the cookie? Why aren't you letting Munchkin recreate the cookie after you delete it? What is the bigger picture here?

Nainsikala_123
Level 1

Re: Overwrite Munckin Cookie

I have 

 

I am trying to create a new cookie on single page application. Based on different user type,  I have to create different cookies.

And invoking the above shared function for updating the cookie.

 

The main concern here is , once the new cookie is set and then trigger visitwebpage activity , on this visitwebpage the params are passing but the cookie is previous one not the updated one.

 

Nainsikala_123
Level 1

Re: Overwrite Munckin Cookie

I tried to create new cookie by munchkin code , but in single page application, cookie is not creating until we reload the page.

 

The use case I want is create different cookie based on user and track their activities on different instances.