谷歌分析和Adwords 延迟 javascript 链接到 App Store 被忽略?

发布于 2024-10-18 23:59:21 字数 1901 浏览 2 评论 0原文

我正在尝试衡量我的 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&amp;label=zqrfCMWh0QEQ_baE8wM&amp;guid=ON&amp;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).

Failed to load resource

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清风挽心 2024-10-25 23:59:21

您应该阻止执行单击操作(浏览到链接),直到您记录它。
在 onclick 属性上添加“return false”:

onclick="recordOutboundLink(params);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":

onclick="recordOutboundLink(params);return false;"

Hope it helps

阳光下慵懒的猫 2024-10-25 23:59:21

我已经设法让我的工作与 _gaq.push();

而不是:

var pageTracker = _gat._getTracker("UA-18180332-1");
pageTracker._trackEvent(category, action);

do:

_gaq.push(['_trackEvent', category, action]);

so 而不是再次获取 pageTracker,因为 _gaq 在页面启动时已经被初始化。只需使用 _gaq 来推送事件跟踪器。另外,请记住,Google Analytics 不会实时更新,而且通常 48 小时内不会更新。

I've managed to get mine to work with the _gaq.push();

instead of:

var pageTracker = _gat._getTracker("UA-18180332-1");
pageTracker._trackEvent(category, action);

do:

_gaq.push(['_trackEvent', category, action]);

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.

墨落画卷 2024-10-25 23:59:21

脚本可能会在 GA 代码完成运行之前进行重定向。您可以尝试将其放在 gaq 上,以便保证它在其余代码之后运行。你的函数可能看起来像这样:

function recordOutboundLink(link, category, action) {
    // Google Analytics
    _gaq.push(['_trackEvent', category, action]);

    // Google Adwords
    _gaq.push(function() {
    var image = new Image(1, 1);
    image.src = "http://www.googleadservices.com/pagead/conversion/1046551421/?value=$8&label=zqrfCMWh0QEQ_baE8wM&guid=ON&script=0";
    });
    _gaq.push(function() {setTimeout('document.location = "' + link.href + '"', 100);});
}

我还没有测试过它,但它与我之前尝试过的东西类似。

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:

function recordOutboundLink(link, category, action) {
    // Google Analytics
    _gaq.push(['_trackEvent', category, action]);

    // Google Adwords
    _gaq.push(function() {
    var image = new Image(1, 1);
    image.src = "http://www.googleadservices.com/pagead/conversion/1046551421/?value=$8&label=zqrfCMWh0QEQ_baE8wM&guid=ON&script=0";
    });
    _gaq.push(function() {setTimeout('document.location = "' + link.href + '"', 100);});
}

I haven't tested it out but it's similar to things I've tried before.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文