How to Redirect to Different Domains/URLs with Google Tag Manager + location.href

Tadashi Shigeoka ·  Thu, August 26, 2021

I’ll introduce how to redirect to different domains or URLs using only HTML + JavaScript with GTM (Google Tag Manager) and location.href.

How to Redirect to Different Domains/URLs with Google Tag Manager + location.href

Background: Want to Redirect Using Only Google Tag Manager

I encountered a case where I wanted to redirect from an LP site to the official site using only Google Tag Manager, so I used location.href to implement the redirect.

The URLs are as follows:

  • LP Site: https://lp.example.com/
  • Official Site: https://example.com/

Prerequisite: Environment Where Only HTML and JavaScript Can Be Edited from Google Tag Manager

When you can’t edit HTML and can’t perform meta refresh redirects, I wrote sample code to add HTML + JavaScript tags from Google Tag Manager and redirect using location.href.

Sample Code for Redirecting with location.href

Here’s the sample code that uses location.href to redirect immediately after page load:

<script type="text/javascript">
  location.href='https://example.com/';
</script>

SEO Perspective Personal Notes

That’s all from the Gemba on wanting to redirect to different domains or URLs using only HTML + JavaScript with location.href.

Reference Information