谷歌分析和Adwords 延迟 javascript 链接到 App Store 被忽略?
我正在尝试衡量我的 Google Adwords 广告系列的转化率和进入 App Store 的正常流量。以前,我的页面上有一个链接“/app_store/”,该链接会加载,等待 1 秒钟,然后继续访问应用商店。
我在某个地方使用 Javascript 找到了一个更优雅的解决方案。对于 AdWords,它加载像素图像;对于分析,它调用 Google Javascript 函数,暂停一小会儿,然后点击链接。
不幸的是它不适合我。 Google Analytics 和 Google Adsense 没有看到任何人访问 App Store(甚至我自己也没有)。
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18180332-1']);
_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);
})();
function recordOutboundLink(link, category, action) {
try{
// Google Analytics
var pageTracker = _gat._getTracker("UA-18180332-1");
pageTracker._trackEvent(category, action);
// Google Adwords
var image = new Image(1, 1);
image.src = "http://www.googleadservices.com/pagead/conversion/1046551421/?value=$8&label=zqrfCMWh0QEQ_baE8wM&guid=ON&script=0"
setTimeout('document.location = "' + link.href + '"', 100)
} catch(err) {}
}
</script>
对于链接:
<a href="http://itunes.apple.com/ae/app/isimplifiedchinese/id377690407?mt=8"
onClick="recordOutboundLink(this, 'Outbound Links', 'http://itunes.apple.com/ae/app/isimplifiedchinese/id377690407?mt=8');return false;">
<img alt="Appstore" src="images/appstore.png"></a>
我在这里做错了什么?
更新23:13 我注意到,如果延迟为 100 毫秒,则会闪现以下错误(我花了一段时间来计时屏幕截图)。
我只根据 Erwan 的建议进行了测试;不确定旧版本中是否也发生过这种情况。如果延迟时间较长,该错误似乎就会消失;为了安全起见,我将其设置为 300ms。
I'm trying to measure conversion for both my Google Adwords campaign and normal traffic going to the App Store. Previously I had a link "/app_store/" on my page that would load, wait 1 second and then continue to the app store.
I found a more elegant solution somewhere using Javascript. For adwords it loads a pixel image and for analytics it calls a Google Javascript function, pauses for a fraction of a second and then follows the link.
Unfortunately it's not working for me. Google Analytics and Google Adsense don't see anyone going to the App Store (not even myself).
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18180332-1']);
_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);
})();
function recordOutboundLink(link, category, action) {
try{
// Google Analytics
var pageTracker = _gat._getTracker("UA-18180332-1");
pageTracker._trackEvent(category, action);
// Google Adwords
var image = new Image(1, 1);
image.src = "http://www.googleadservices.com/pagead/conversion/1046551421/?value=$8&label=zqrfCMWh0QEQ_baE8wM&guid=ON&script=0"
setTimeout('document.location = "' + link.href + '"', 100)
} catch(err) {}
}
</script>
And for the link:
<a href="http://itunes.apple.com/ae/app/isimplifiedchinese/id377690407?mt=8"
onClick="recordOutboundLink(this, 'Outbound Links', 'http://itunes.apple.com/ae/app/isimplifiedchinese/id377690407?mt=8');return false;">
<img alt="Appstore" src="images/appstore.png"></a>
What am I doing wrong here?
Update 23:13
I noticed that if the delay is 100ms, the following error flashes by (it took me a while to time the screenshot).
I only tested this with Erwan's suggestion; not sure if it also happened in the old version. The error seems to go away for longer delays; I set it to 300ms to be on the safe side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该阻止执行单击操作(浏览到链接),直到您记录它。
在 onclick 属性上添加“return false”:
希望有帮助
You should prevent the click action (browse to the link) from beeing executed until you record it.
On the onclick attribute add a "return false":
Hope it helps
我已经设法让我的工作与
_gaq.push();
而不是:
do:
so 而不是再次获取 pageTracker,因为 _gaq 在页面启动时已经被初始化。只需使用 _gaq 来推送事件跟踪器。另外,请记住,Google Analytics 不会实时更新,而且通常 48 小时内不会更新。
I've managed to get mine to work with the
_gaq.push();
instead of:
do:
so instead of getting the pageTracker again since the _gaq has already been initialized when the page started. simply use the _gaq to push the event tracker. Also, keep in mind, google analytics does not update real time and more often than not it doesn't gets updated for 48 hours.
脚本可能会在 GA 代码完成运行之前进行重定向。您可以尝试将其放在 gaq 上,以便保证它在其余代码之后运行。你的函数可能看起来像这样:
我还没有测试过它,但它与我之前尝试过的东西类似。
It's possible that the script is redirecting before the GA code has finished running. You could try placing it onto the gaq so it is guaranteed to run after the rest of the code. Your function might then look like this:
I haven't tested it out but it's similar to things I've tried before.