How to Redirect to Different Domains/URLs with Google Tag Manager + location.href
I’ll introduce how to redirect to different domains or URLs using only HTML + JavaScript with GTM (Google Tag Manager) and location.href.
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:
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.
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>
That’s all from the Gemba on wanting to redirect to different domains or URLs using only HTML + JavaScript with location.href.