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 ?
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.
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 ?
Again, I need to see the code you're attempting to use to do this. You haven't provided enough information.
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);
})();
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?
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.
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.