Deferred Munchkin - not logging Visit Web Page
Hi everyone,
I tried to implement Sanford's solution for deferring the Munchkin.Init() call for GDPR compliance on Marketo Landing Pages, as per https://blog.teknkl.com/conditionally-loading-munchkin-on-marketo-lps-for-gdpr-related-policies/.
My problem was initially that - directly after accepting the cookie - the "Visit Web Page" event was not captured against the targeted customer, but as anonymous.
It was stripping the mkt_tok and lost the identification of the customer. I understand it's working as designed for good reasons, but it’s hitting me on the deferred scenario.
I now tried to bring back the mkt_tok as per Sanford’s solution here: https://blog.teknkl.com/restoring-the-mighty-mkt_tok/.
So I am running
if (window.__mktTokVal && history.replaceState) {
var restoredLoc = document.createElement("a");
restoredLoc.href = document.location.href;
restoredLoc.search += (restoredLoc.search ? "&" : "") + "mkt_tok=" + window.__mktTokVal;
history.replaceState({}, null, restoredLoc.href);
}
Munchkin.init();
right after the cookie has been accepted – et voila – the “Visit Web Page” activity is being recorded again as expected now.
But – now I got the mkt_tok in the URL again… So I tried to remove it by running
window.history.pushState({}, document.title, document.location.origin + document.location.pathname);
after the Munchkin.Init().
But – you probably guessed it by this point – we’re back to square one where the “Visit Web Page” doesn’t get recorded anymore… It’s probably too fast removing the URL before the Munchkin.Init() can complete its stuff?
Does anyone have any clever idea on how to make it work?
Example:
If you want to give it a try, here’s the link for my test customer to play around with. My scenario starts with the customer receiving an email with a link to a Marketo Landing Page (https://exploremore-qa.techdata.com/Q0PB08Q0Zi25x041H00w3o0).