Prevent redirects & fake form submits in Google Tag Manager preview mode

0
107
READ IN < 1 MINUTE

Often when adding tracking in Google Tag Manager you will be redirected to a thankyou page. In the Google Tag Manager preview mode the click event is lost here which makes identifying variables to assign to the click difficult. This also created fake form submissions in a business account. (see also our post on the Chrome extension for excluding your IP data in GA).

To combat thus – Simply enter the JavaScript console (Ctrl+Shift+J in Google Chrome) and enter the following script:

window.addEventListener('beforeunload', function(e) {
  e.preventDefault();
  e.returnValue = '';
});

Now when you submit the form – just click cancel. You can then review any click events and variables assigned to the form submit

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.