Javascript重定向与谷歌分析 [英] Javascript Redirect with Google Analytics

查看:135
本文介绍了Javascript重定向与谷歌分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





该重定向文件的代码:

 < head> 
< script type =text / javascript>
函数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']); <! - 我有我的真实ID - >
_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!您将在3秒内重定向到新的更好的应用。< / h2>
< / body>
< / html>

只有当我不包含我的Google Analytics代码时,才能用作重定向。我试着移动代码而不做任何修改。



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



我试过PHP重定向没有成功,我非常确定htaccess重定向不会帮助,虽然我愿意接受建议。

我使用JavaScript重定向的原因是,我可以继续使用Google Analytics进行跟踪,并显示一条消息或延迟创建自定义页面。



感谢您的帮助。如果您知道某个解决方案,请不要输入任何JS。

使用元刷新就像一个魅力!遗产FTW!谢谢,@Balexandre

 < html> 
< head>
< meta http-equiv =refreshcontent =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!您将在5秒内重定向到新的更好的应用。< / h2>
< / body>
< / html>

RECAP:我现在可以在使用Google Analytics跟踪这些重定向时重定向!



元刷新(摘自维基百科

示例

放置在5秒后刷新页面:

 < meta http-equiv =refreshcontent =5> 

重定向至 http:// 5秒后显示:

 < meta http-equiv =refreshcontent =5 ; url = http://example.com/> 

重定向至 http://

 < meta http-equiv =refreshcontent =0; url = HTTP://example.com/> 


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

The code for that redirect file:

<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>

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

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

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

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.

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

解决方案

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>

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

Meta Refresh (Taken from wikipedia)

Examples

Place inside to refresh page after 5 seconds:

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

Redirect to http://example.com/ after 5 seconds:

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

Redirect to http://example.com/ immediately:

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

这篇关于Javascript重定向与谷歌分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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