使用 Google Analytics 进行 Javascript 重定向 [英] Javascript Redirect with Google Analytics

查看:24
本文介绍了使用 Google Analytics 进行 Javascript 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助弄清楚如何在包含 Google Analytics(分析)代码的同时成功重定向.

I need help figuring out how to successfully redirect while including Analytics code.

该重定向文件的代码:

<head>
<script type="text/javascript">
function delayedRedirect(){
    window.location = "https://market.android.com/developer?pub=Fractal%20Systems"
}
</script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-1234567-8']); <!--I have my real ID there-->
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<body onLoad="setTimeout('delayedRedirect()', 3000)">
<h2>ADW.BuuF.Theme is no more! You will be redirected to new and better apps in 3 seconds.</h2>
</body>
</html>

仅当我不包含我的 Analytics 代码时,这才用作重定向.我试过在不做任何更改的情况下移动代码.

This works as a redirect only if I don't include my Analytics code. I've tried moving the code around with no change.

问题如何添加任何类型的重定向,并且仍然能够使用 Google Analytics(分析)进行跟踪?

QUESTION How can I add a redirect, of any kind, and still be able to track with Google Analytics?

我尝试过 PHP 重定向但没有成功,虽然我愿意接受建议,但我很确定 htaccess 重定向不会有帮助.

I've tried PHP redirects with no success and am pretty sure htaccess redirects wont help although I'm open to suggestions.

我使用 JavaScript 重定向的原因是,我可以继续使用 Google Analytics(分析)进行跟踪,并显示一条小消息或制作带有延迟的自定义页面.

The reason I'm using a JavaScript redirect is so I can continue to track with Google Analytics and also show a little message or make a custom page with the delay.

感谢您的帮助.不必是 JS,如果您知道解决方案,欢迎任何输入.

Thanks for any help. Doesn't have to be JS, please, any input is welcome if you know of a solution.

推荐答案

使用 元刷新 很有魅力!传统FTW!谢谢,@Balexandre

Using meta refresh worked like a charm! Legacy FTW! Thanks, @Balexandre

<html>
<head>
<meta http-equiv="refresh" content="5; url=https://market.android.com/developer?pub=Fractal%20Systems">
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-1234567-8']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<body>
<h2>ADW.BuuF.Theme is no more! You will be redirected to new and better apps in 5 seconds.</h2>
</body>
</html>

回顾:我现在可以在使用 Google Analytics 跟踪这些重定向的同时进行重定向!

RECAP: I am now able to redirect while tracking those redirects using Google Analytics!

元刷新(取自维基百科)

示例

放置在 5 秒后刷新页面:

Place inside to refresh page after 5 seconds:

<meta http-equiv="refresh" content="5">

5 秒后重定向到 http://example.com/:

<meta http-equiv="refresh" content="5; url=http://example.com/">

立即重定向到http://example.com/:

<meta http-equiv="refresh" content="0; url=http://example.com/">

这篇关于使用 Google Analytics 进行 Javascript 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆