Heads Up: Fix for stripmkttok.js | Community
Skip to main content
Casey_Grimes2
Level 10
April 1, 2019
Question

Heads Up: Fix for stripmkttok.js

  • April 1, 2019
  • 1 reply
  • 2614 views

It looks like there was a new piece of code deployed to all Marketo landing pages recently, /js/stripmkttok.js, and it has been automatically added to Marketo landing pages. This code is intended to remove the tracking parameter mkt_tok from end users' view via the HTML5 History API once the page is fully loaded. Unfortunately, this code doesn't work quite the way it should and often leaves extraneous characters if you are supplying your URL with other parameters (such as analytics tracking). This can be fixed by some alternate methods of approaching the problem; for example, using the following function corrects the issue:

var stripParam = function (key) {

var baseUrl = [location.protocol, "//", location.host, location.pathname].join(""),
urlQueryString = document.location.search,
newParam = key,
params = "?" + newParam;

if (urlQueryString) {
var removeRegex = new RegExp("([\?&])" + key + "=[^&;]+[&;]?");

params = urlQueryString.replace(removeRegex, "$1");
params = params.replace( /[&;]$/, "" );
}

params = params == "?" ? "" : params;

window.history.replaceState(
{}, "", baseUrl + params + window.location.hash
);
};
stripParam("mkt_tok");

If this functionality could be fixed as soon as possible, it would be appreciated—this has caused some unintended side effects.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

KellyJoHorton
Level 3
April 11, 2019

Insert FacePalm emoji here.

Kelly Jo HortonSenior Client PartnerEtumos503.928.1928khorton@etumos.com